Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program that calculates how much change should be given and determine th

ID: 3618854 • Letter: W

Question

write a program that calculates how much change should be given and determine the number of each type of coin to dispense. We will assume that all prices are multiples of 5 cents and that change can be returned using only quarters (25 cents), dimes (10 cents) and nickels (5 cents). For now we will just input the amount paid and the price of the item from the keyboard and the change will be output to the screen. Sample output # 1: Enter cost of item (in cents): 65 Enter amount paid (in cents): 100 You paid 100 cents for something that cost 65 cents. Giving 35 cents in change. Quarters: 1 Dimes: 1 Nickels: 0 YOU SHOULD GIVE THE LEAST NUMBER OF COINS. FOR INSTANCE IN THE EXAMPLE ABOVE. THE CHANGE IS NOT 7 NICKELS (35 CENTS). IT IS 1 QUARTER AND 1 DIME. 7 NICKELS (5+5+5+5+5+5+5) WRONG!!! 1 QUARTER (25) + 1 DIME (10) = 35 CENTS (YOUR MACHINE SHOULD GIVE THE LEAST CHANGE)

Explanation / Answer

publicstatic void main(String[]args) { // keyboardinput Scanner kb= newScanner(System.in); System.out.print("Enter costof item (in cents): "); int cost= kb.nextInt(); System.out.print("Enteramount paid (in cents): "); int paid= kb.nextInt(); //calculations int change= paid -cost; System.out.println("You paid" + paid + " cents for somethingnthat cost " + cost + " cents."); System.out.println("Giving" + change + " cents inchange."); int quarters= 0; int dimes= 0; int nickels= 0; while(change>=25) { quarters++; change -= 25; } while(change>=10) { dimes++; change -= 10; } while(change>=5) { nickels++; change -= 5; } System.out.println("Quarters: "+quarters); System.out.println("Dimes: "+dimes); System.out.println("Nickels: "+nickels); }