Week 6 Homework

Before you start

Read the instructions and watch the video posted in Lab Assignment 6 for using GitHub Classroom to access and submit your program.

Use the link provided by your professor to access the GitHub repo with the starter code.

Complete the following program

Write a program that mimics the operations of a vending machine. More specifically, the program reads amounts of money that are inserted into the vending machine, asks the user to select an item, and then prints the change that’s returned to the user.

The GitHub repo contains two files: VendingMachineDriver.java and VendingMachine.java. VendingMachineDriver.java contains the main() method and should not be modified.

VendingMachine.java requires the following specification:

The following sample shows the operation of the program:

Sample Output

Welcome to Sean's vending machine!

Options: (i)nsert money, (s)elect an item, (q)uit
Enter i, s, or q ==> s
Sorry, you can't select an item as you haven't inserted money yet.
Options: (i)nsert money, (s)elect an item, (q)uit
Enter i, s, or q ==> d
Invalid selection.
Options: (i)nsert money, (s)elect an item, (q)uit
Enter i, s, or q ==> i
Amount of money inserted: -1
Invalid payment. Must enter a number greater than zero.
Amount of money inserted: 0
Invalid payment. Must enter a number greater than zero.
Amount of money inserted: 2
Balance: $2.00
Options: (i)nsert money, (s)elect an item, (q)uit
Enter i, s, or q ==> s
Select item's price: -1
Invalid price. Must enter a number greater than zero.
Select item's price: 0
Invalid price. Must enter a number greater than zero.
Select item's price: 10
Invalid price. Price exceeds payment.
Select item's price: .32
Your change
===========
6 quarter(s)
1 dime(s)
1 nickel(s)
3 penny(ies)

Options: (i)nsert money, (s)elect an item, (q)uit
Enter i, s, or q ==> i
Amount of money inserted: 12.43
Balance: $12.43
Options: (i)nsert money, (s)elect an item, (q)uit
Enter i, s, or q ==> s
Select item's price: 8.74
Your change
===========
14 quarter(s)
1 dime(s)
1 nickel(s)
4 penny(ies)

Options: (i)nsert money, (s)elect an item, (q)uit
Enter i, s, or q ==> q
Thank you for using Sean's vending machine!

Submission Instructions:

Add DONE to the README and then Commit and Push your code to GitHub Classroom.

Acknowledgement

This laboratory assignment was adapted from an assignment by John Dean and developed by Prof. Sean Jones