Programming 2. Exact Change Calculator
You are to develop a program to help cashiers in a retail store by computing the exact changes to be paid to cash customers.
Requirement
You shall create a ChangeCalculator
class. The program must compute the change in the way that the
change consists of the least number of paper bills and coins. To achieve this, you should
compute the number of bills and coins from the highest denomination to the lowest denomination.
Although the U.S. government issues a variety of dollar bills and coins, we only consider the following denomination of paper bills,
$1, $2, $5, $10, and $20
and the following denomination of coins,
1, 5, 10, and 25 cents
which are most commonly stocked in the retail store.
Your program should prompt the cashier to enter the balance to be paid, the amount of cash received from the customer, and the program displays the change in the number of bills and coins in the domination above on the standard output. You must consider four cases below:
- The cash received is too little. Your program’s output must be in the format exhibited in the example below,
$ java ChangeCalculator Enter total price including cents to be paid: 53.24 Enter the cash the customer is paying: 40 Exact Change Calculation Total price to be paid: $53.24 The cash received: $40.0 Sorry. Not enough cash.
- The cash received is too much – we consider the cash is too much if the excessive cash is $100 or more. Your program’s output must be in the format exhibited in the example below,
$ java ChangeCalculator Enter total price including cents to be paid: 53.24 Enter the cash the customer is paying: 160 Exact Change Calculation Total price to be paid: $53.24 The cash received: $160.0 Too much cash!
- The cash received is exactly the balance to be paid. Your program’s output must be in the format exhibited in the example below,
$ java ChangeCalculator Enter total price including cents to be paid: 53.24 Enter the cash the customer is paying: 53.24 Exact Change Calculation Total price to be paid: $53.24 The cash received: $53.24 Exact payment. No changes.
- The cash is adequate, but we need to give the customer the change. The program’s output must be in the
format exhibited in the example below,
$ java ChangeCalculator Enter total price including cents to be paid: 53.24 Enter the cash the customer is paying: 60 Exact Change Calculation Total price to be paid: $53.24 The cash received: $60.0 Give to the cusotmer: $20 bill: 0 $5 bill: 1 $2 bill: 0 $1 bill: 1 Quarter: 3 Dime: 0 Nickle: 0 Penny: 1
Implementation Consideration
Floating numbers are not exact. If you are using floating numbers to represent the balance to be paid and the cash received, you should convert the balance and the cash to cents first, do the calculation using cents, however, display the result in dollars and cents. In this way, we can eliminate the case that some of your result is off by one penny.
The format must be exact; otherwise, CodeLab will reject the output.
Submission
Submit your work on https://codelab.turingscrat.com. Look for “Project 2” under “Programming Projects”.
Submission Deadline
The deadline is posted on the class Website.