Java Bootcamp – Workbooks and Challenges
)}

Vending Machine – Part 4

In this workbook, you will add interactivity to the application.

Task 1 – Set up Scanner()


Set up Scanner() and pick up the requested row and spot.

System.out.print("Pick a row: "); 
// pick up row. 
System.out.print("Pick a spot in the row: "); 
// pick up spot.

Task 2 – Dispense a drink

Dispense a drink from the machine at the requested row and spot. Then, print the machine: System.out.println("\n" + machine);

The quantity of the requested item should decrease by one.

Task 3 – Create a loop


Run your code in an infinite while loop. You'll notice the vending machine stops dispensing an item when it runs out.

if the machine dispenses a drink:

print("\nEnjoy your drink! Press 1 to purchase another: ")

otherwise:

print("\nSorry, we're out of this item. Press 1 to purchase another: ")

If the user enters anything that isn't 1, break the loop.

Good Luck!


Feedback Summary
4.8
39 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.