Question: What changes to the ChangeMaker program in Listing 2.3 are necessary if it also accepts coins for one dollar and half a dollar? Listing 2.3

What changes to the ChangeMaker program in Listing 2.3 are necessary if it also accepts coins for one dollar and half a dollar?


Listing 2.3

import java.util.Scanner; public class ChangeMaker { public static void main (String[] args) { int amount, originalAmount, quarters, dimes, nickels, pennies; System.out.printin(

import java.util.Scanner; public class ChangeMaker { public static void main (String[] args) { int amount, originalAmount, quarters, dimes, nickels, pennies; System.out.printin("Enter a whole number from 1 to 99."): System.out.println("I will find a combination of coins"); System.out.println("that equals that amount of change."): Scanner keyboard = new Scanner (System.in); amount = keyboard.nextInt (); originalAmount = amount; quarters = amount / 25; amount = amount % 25; dimes = amount / 10; 25 goes into 87 three times with 12 left over. 87 / 25 is 3. amount = amount % 10; nickels = amount / 5; 87 % 25 is 12. 87 cents is three quarters with 12 cents left over. amount = amount % 5; pennies = amount; System.out.println(originalAmount + " cents in coins can be given as:"); System.out.println(quarters + " quarters"); System.out.println(dimes + " dimes"); System.out.printin(nickels + " nickels and"); System.out.println(pennies + " pennies"): }

Step by Step Solution

3.31 Rating (166 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Add variables int dollars halfDollars Change the prompt Systemoutprin... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java An Introduction to Problem Solving and Progra Questions!