Question: Your task in this assignment is to write a simple class definition for a vending machine in Java. The class should have: Attributes Soda count

Your task in this assignment is to write a simple class definition for a vending machine in Java. The class should have:

Attributes Soda count Money credit (how much money has been inserted)

Methods Add money Vend Restock Constructor

For simplicity sake, you may assume that the machine can hold up to 50 of one type of soda; you may also assume that all sodas cost $0.65. When adding money, simply take in a floating-point number representing how much money to add (i.e. you do not have to manage different coins).

Be sure to make sure that enough money was added to the machine before a soda is vended. Also, when a soda is vended, return the appropriate change (i.e. if more than $0.65 was added to the machine, then return the extra money). Again, don't worry about managing different kinds of coins just display the amount returned.

When the machine is "restocked," just set the soda count to the maximum that the machine will hold.

Once you have written the class, create a main/driver program that interacts with an instance of the class. Your program should present a menu of options to the user and process the user's choice; use creativity and object-oriented design in your solution.

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!