# Redeem Coupon

• January 30th, 2013, 02:44 AM
anthonychin
Redeem Coupon
Hi All,

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

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.)
• January 30th, 2013, 04:07 AM
curmudgeon
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!