Question: A clerk in the U.S. store often encounters the problem of given change for a purchase because customers usually dont want to receive a lot
A clerk in the U.S. store often encounters the problem of given change for a purchase because customers usually dont want to receive a lot of coins: 1c, 5c, 10c, 25c. What is an optimal solution to minimize the number of coins for a change?
A) Develop an iterative greedy algorithm to have the minimum number of coins for a change x cents.
B) The coins consist of U.S. coins which are available. The owed amount is 36 cents. What is an optimal solution?
C) Suppose that 12-cent coin with the U.S. coins is available. The owed amount is 16 cents. What is an optimal solution?
** So I believe the answer for B is 3 coins (quarter, dime and a penny) and C is also 3 (dime, nickel and a penny). I am fairly confident in those answers. What I mainly need help with is A. I need help writing the code (in JAVA). my thought process was something like this:
Checks total change then divides by $0.25. gives them that many quarters that divide into it. Check remaining change then divide by $0.10. gives them that many dimes that divide into it. Check remaining change then divide by $0.05. gives them that many nickels that divide into it. Check remaining change then divide by $0.01. gives them that many pennies that divide into it. IF AT ANY TIME REMAINING CHANGE = 0, exit the algorithm.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
