Question: A programmer has written code for a machine that dispenses items. Part of the program should allow the user to pay for their selected item.

A programmer has written code for a machine that dispenses items. Part of the program should allow the user to pay for their selected item. The user should keep inserting coins until they have paid for their purchase. Once the price of the item has been inserted the program should display a message asking the user to collect their item and, if applicable, also show the correct change owed to them.

If the user cancels their purchase at any time up until they have paid the price of the item, they will be asked to collect the correct amount of money they have inserted as change. Any invalid input should cause an error message to be displayed to the user.

The complete program compiles and runs, but the program does not behave as expected. There are many logic errors in the program. Find and fix these errors.

A programmer has written code for a machine that dispenses items. Part

public void dispenseItem (double price) double amount = 0; char choice = '. Scanner console = new scanner (System ,in) ; do System.out.println ("A. $1.00"); System.out.println("B. $0.50"); System.out.println ("C. $0.20"); System.out.println ("D. $0.10"); System.out.println ("Z. Cancel"); System. out.print("Please select: "); choiceconsole.nextLine().charAt(0); switch (choice) case 'A': amount+= 1.00; break ; case 'B': amount+= 0.50; break ; case 'C' : amount+= 0.20; break ; case 'D': amount+= 0.10; break ; case 'Z' default: System.out.print("Invalid - Press enter to continue") ; console.nextLine () } while (choice != 'Z'll amount 0) II (choice != 'Z' && amount > price)) if (choice != 'Z') System.out.println ("Your change is $" + price); amount amoun t

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!