Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Redeem Coupon

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Redeem Coupon

    Hi All,

    I don' t know how to create java code for this assignment.Can help?

    Task Statement
    In general there are two types of coupons: cash coupon and discount coupon.
    Cash coupon has a face value greater than 1, and can be used as cash to buy things. However, the price after discount cannot be less than zero. For example, if you use a $10.00 coupon to buy a pen worth $5.80, you would spend $0 in cash. However, you will not get any change from the shop.
    However, there is an “theoretical amount” involved. In the above example, the “theoretical amount” you need to pay is -$4.20, which means you will “lose” $4.20 if you use a $10 coupon to buy the pen. If you use a $8 coupon instead, the “theoretical amount” will be -$2.20, which means you “lose” less money. The better choice is hence the $8 coupon, since you can save the $10 coupon for something more expensive.
    Discount coupon has a discount rate smaller than 1. For example, if the discount rate is 0.2, it means 20% off the price. If you buy a pen worth $5.80 with this coupon, you would pay $4.64.
    You are to create a Java service class named Coupon to represent coupon. The attributes are name of a coupon, and rate which represents either the face value or discount rate of the coupon. You also need to create a method inside this class to calculate what you need to pay (the “theoretical amount”) when you use a coupon.
    You are also to write a client Redeem class to read inputs as described below, and compute the best option. If there are two or more options that give the best result, you will pick the first one among them that appears in the input (as illustrated in sample input #3 below).
    Input
    The first line of the input contains two positive numbers, an amount (of type double) and an integer N (1 ≤ N ≤ 10) which indicates the number of coupons. In the subsequent N lines, each line contains information about a coupon: its name followed by face value or discount rate.
    (The above symbol N is used to ease explanation. In your program, you should give more descriptive variable names and follow Java naming convention.)
    Output
    The output contains a single line, stating which is the best coupon to use, and the amount you need to pay, correct to 2 decimal places. (Sometimes, due to rounding differences, your final value may differ from the value in the expected output in the second decimal digit. In this case, as long as your formula is correct, it will be marked as correct.)


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Redeem Coupon

    You need to be much more specific in your question. Exactly where are you stuck? What have you done so far? What isn't working about the code you have? We can't do the assignment for you of course, but we can help answer specific questions that you may have. Until you ask them, a great site for learning Java is the Java Tutorials Really Big Index. Also some great suggestions for newbies who are totally lost and written by Java educator Patricia Shanahan can be found here: So, You Need to Write a Program but Don't Know How to Start. Much luck!

Similar Threads

  1. I can not redeem the action of a button within a table.
    By pezinho45 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 22nd, 2012, 08:35 AM