Question
Write a program names ChangeDriver and start with the answer for the Change application from module 2. Add a while loop that ends when the
Write a program names ChangeDriver and start with the answer for the Change application from module 2. Add a while loop that ends when the user types in false to a question if there are more purchases. Output the number of purchases, the total cost of all purchases, and the total number of coins returned to the user Change application to start with: =================================
public class Change {
public static void main(String[] args) { Scanner scan = new Scanner(System.in); int numQ=0; int numD=0; int numN=0; System.out.println("How much did the vending machine item cost?"); int cost = scan.nextInt(); int refund = 100 - cost; if (cost100 || cost%5!=0) System.out.println("Not a valid cost. Must be between 25 and 100 in increments of 5"); else if (cost==100) System.out.println("No change!"); else { numQ = refund/25; int left = refund % 25; numD = left/10; left = left%10; numN = left/5; System.out.println(" Your change is "); if (numQ>0) System.out.println(" " +numQ + " quarters"); if (numD>0) System.out.println(" " +numD + " dimes"); if (numN>0) System.out.println(" " + numN + " nickels"); }
}
} ================================= SAMPLE OUTPUT: THEN Repeat the program above but name it ChangeFor and use a for loop that asks the user for the number of purchases and loops that many times. The output will look identical. NOTE: Make certain that the for loop does not count invalid input runs as a valid run. 2 Programs should be sumbitted here ( ChangeDriver & ChangeFor )
Sample Output for Change (both versions will look the same) except how the loop asks questions. The for loop will ask how many items at the top and not have the "More purchases?(truefalse)" How much did the vending machine item cost? 54 Not a valid cost. Must be between 25 and 100 in increments of 5 More purchases? (true/false) true How much did the vending machine item cost? 100 No change! More purchases? (true/false) true How much did the vending machine item cost? 35 Your change is 2 quarters 1 dimes 1 nickels More purchases? (true/false) true How much did the vending machine item cost? 60 Your change is 1 quarters 1 dimes 1 nickels More purchases? (true/false) false You had 3 purchases for a total cost of 195Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started