(15 points)
In this assignment, you practice using methods and doing arithmetic in java.
You are planning a trip to Canada. Of course, you will stop by a gift shop to bring back some souvenirs to your family and friends. Canadian gift shops gladly accept US currency. However, they give you back your change in Canadian dollars. Curious about the transaction, you want to try different scenarios. Given an amount of US money, what can you buy? How much canadian money are you left with? A java program would be the perfect tool to answer all of your questions.
To make it simple, we will assume that the user only wants to buy any of the following items:
These prices don't include taxes. The tax rate is 11.7% (this may not be the current rate but we will keep this number for the sake of our calculation).
Once taxes are included, it is likely that the total amount will not have a whole number of cents. When that is the case, always round the number of cents to the closer integer. For instance, if an amount is 143.123, it is rounded to 143.12. But 143.127 is rounded to 143.13 and 143.125 is rounded to 143.13.
We will use the exchange rate: 1 US dollar = 1.43 CA dollar (again this may not be current)
The customer can buy at most 100 items of each.
Moreover, the owners of the gift shop offer the customer the possibility of getting a discount. If the amount of CA dollars in the total is made of non-decreasing digits (when read from left to right) and the amount of CA cents in the total is made of non-increasing digits (also when read from left to right), then the customer gets an additional 10% discount. For instance, if the total is 114.50 CA dollars, since {1,1,4} is a sequence of non decreasing digits and {5,0} is a sequence of non increasing digits, the customers gets an additional 10% and pays 114.50 x 0.9 = 103.05. However, if the total is 21.50 CA dollars, since 2 > 1, the customer doesn't get any discount.
We will assume that only the following Canadian currency is available
in paper bills: CAD 5, 10, 20, 50 and 100 (CAD means Canadian dollar)
in coins (notice that there is no penny)
To store all of these numbers (except the currency amounts), use constants (see the sample file).
Your program should:
Try to break up the problem into simple tasks using methods. If you find yourself writing the same piece of code several times, put that piece of code in a method and call that method several times. If you find yourself writing a lot of code within one method, break up that code into several methods. It would be a mistake to write all of the code in takeAndProcessOrder. The sample file lists other methods that you might find helpful. You don't have to use exactly the same approach.
Display all of the money amounts with 2 digits after the decimal point (use the class java.text.DecimalFormat).
Here is a code snippet that should help you:
/* don't forget the statement import java.text.DecimalFormat at the beginning of your code */
DecimalFormat twoDigits = new DecimalFormat("0.00");
double number=3.256;
System.out.println("number="+twoDigits.format(number)); /* displays number=3.26 */
Make sure that your program is readable by someone else than you. Style counts!!!
Write your program within the sample file provided, which gives a basic structure for your program. Your work will be graded on a battery of sample tests. The tests assume that your code uses the UW Library Input class as suggested in the sample file. Don't use another approach to get the input for full credit.
Check this text file to compare your computations with some sample runs. Good luck!
Your program has to be your own.