Starting from:
$30

$24

Make Change Calculator Solution

in this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you will re-do the program to give change from a specific number of available coins.




Part A: Basic Change for a dollar:

In this version of the program you will give change for a dollar in the most efficient manner (i.e., fewest number of coins of each type).




A sample run of the program might look as follows:

Welcome to the Make Change calculator!




What value would you like change for? (1-100 cents, or 0=quit): 23




For 23 cent(s) I give: 0 quarters, 2 dimes, 0 nickels, 3 pennies




What value would you like change for? (1-100 cents, or 0=quit): 1




For: 1 cent(s) I give: 0 quarters, 0 dime, 0 nickels, 1 pennies




What value would you like change for? (1-100 cents, or 0=quit): 100




For: 100 cent(s) I give: 4 quarters, 0 dime, 0 nickels, 0 pennies




What value would you like change for? (1-100 cents, or 0=quit): 0




Thanks for using the Make Change calculator!




Part A Required Elements: the following features must be present for full credit:

Declare as global only those items that must be used across methods
Minimize the code inside main, but include a loop so the user can enter change values multiple times (entry of a zero terminates the loop)
Code a separate method to obtain and validate the input value as being from 0 to 100

Validation should include a try/catch structure to avoid crashing the program on non-integer input
Code a separate method to determine and print the actual change returned



Part B: Perfect change with specific coin counts:




The claim has been made that when receiving change for a any amount up to $1 you can always make that change with only the following coins: 3 quarters, 1 dime, 2 nickels, and 5 pennies. You will write a program to test that assumption. To do this, you will add a method to MakeChange that runs at the beginning of the program to ask if a specific set of coins is being used (but note that the program may still run in the old way also). A sample run might be as follows:




Welcome to the Make Change calculator!

Do you have a specific set of coins for making change? (Y/N): Y

 

No. of Quarters: 3

No. of Dimes: 1

No. of Nickels: 2

No. of Pennies: 5




What value would you like change for? (1-100 cents, 101=New Coin set, or 0=quit): 23




For 23 cent(s) I give:

0 quarters, 1 dime, 2 nickels, 3 pennies leaving

3 quarters, 0 dime, 0 nickels, 2 pennies




What value would you like change for? (1-100 cents, 101=Coin set (Y/N), or 0=quit): 100




For: 100 cent(s) I give:

3 quarters, 1 dime, 2 nickels, 5 pennies leaving:

0 quarters, 0 dime, 0 nickels, 0 pennies




What value would you like change for? (1-100 cents, 101=Coin set (Y/N), or 0=quit): 101




Do you have a specific set of coins for making change? (Y/N): Y




No. of Quarters: 3

No. of Dimes: 1

No. of Nickels: 2

No. of Pennies: 2




What value would you like change for? (1-100 cents, 101=New Coin set, or 0=quit): 4




I could not make change for: 4 cents (I am short: 2 cents)




What value would you like change for? (1-100 cents, 101=New Coin set, or 0=quit): 0




Thanks for using the Make Change calculator!

Note that in this version the ‘how much change’ question now has a new option: 101. If the user selects this option, the program should run the method that asks for the coin counts (i.e., the same method that now runs at the beginning of the program).




Now during operation, the program must know if a specific set of coins has been entered: if so, then a new method called ‘PerfectChange’ will be used to determine the coins to be given in change. But, if a specific set of coins was not used, the program should operate in exactly the same way is it did in Part A (i.e., giving the fewest possible coins as change for $1). Also note that in the ‘specific coins’ scenario, it is possible that perfect change cannot be given.




Call the program MakeChange.java and zip the finished netbeans project from the top-level folder. Submit it through blackboard as a separate zip file, as discussed in class.







Extra Credit (10 points):




Add another option to the ‘how much change’ question (i.e., item 102) that produces an ‘all’ output result. In other words, if the user enters 102, the program should loop to produce results for all values 1 through 100 (using the coin counts if entered or the original ‘most efficient’ method). This option should not fundamentally modify any of the existing methods in the program, but merely add a new method to loop through all possible values from 1 – 100 (making use of the other program methods, as needed – although new parameter passing may be needed, depending on program structure).

More products