Question: Java Write a program that mimics the operations of several vending machines. More specifically, the program simulates what happens when the user chooses one of

Java

Write a program that mimics the operations of several vending machines. More specifically, the program simulates what happens when the user chooses one of the vending machines, inputs money and picks an item from the vending machine. Assume there are two vending machines: one for drinks and one for snacks. Each vending machine contains several items. The name, price, and quantity of each item is given in two text files; one named drinks.txt for the drinks vending machine and the other named snacks.txt for the snacks vending machine.

The format of the input values is comma-separated. The items listed should be organized in the file with the following order: name, price, quantity. Here are some example items:

Milk,2.00,1

OJ,2.50,6

You will need to create/complete three classes for this homework assignment: Item, VendingMachine, and VendingMachineDriver.

Within your VendingMachine class, include these methods:

VendingMachine This constructor method will take in the name of the input file and create a vending machine object. A vending machine object will contain an array of Itemobjects called stock and an amount of revenue earned. This constructor method has been completed for you and should work appropriately once you have completed the rest of this class and the other class definitions.

vend This method will simulate the vending transaction after a valid amount of money and an item selection are entered. This method will decide if the transaction is successful (enough money or item) and update the vending machine appropriately.

outputMessage This method will print an appropriate message depending on the success of the transaction. If the user does not have enough money to buy the chosen item, the vending machine should prompt the user to enter more money or exit the machine. If the vending machine is out of the chosen item, the program will print an apology message and prompt the user to choose another item or exit the machine. If there is enough money for the item selected, then the vending machine will give the user the item and return the change.

printMenu This method prints the menu of items for the chosen vending machine.The Item class needs to include the following data variables: description as a String price as a double quantity as an int

Within your VendingMachineDriver class, include a main method as the starting point for your solution that creates the vending machine objects appropriately and then use a loop that continues interacting with the vending machines until the user enters X to exit. See the sample session for details. As you implement your solution, you might find that some methods contain some repeated coding logic. To avoid unnecessary redundancies in your code, have these methods call an appropriate helper method.

Sample Run:

Java Write a program that mimics the operations of several vending machines.

More specifically, the program simulates what happens when the user chooses oneof the vending machines, inputs money and picks an item from the

Welcome to Jeremy's Super Vending Machines I sense you are hungry or thirsty. Please select a vending machine rinks B-Snacks X-Exit. a Menu Price Qty Item Item Milk 2.00 2.50 OJ Water 1.50 10 2.25 Soda Coffee 25 3.00 Monster Please enter some money into the machine (enter -1 to exit): 4.25 You now have $4.25 to spend. Please make a selection (enter 0 to exit) 1 You have bought Milk for $2.00 Your change is $2.25. Please select a vending machine rinks B-Snacks X-Exit B A-D Menu Item Item Price Qty Gummies 50 Chips 1.00 1.25 Raisins Pretzels 1.50 1.75 Cookie 1.25 Peanuts 0.75 Gum

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!