Question: Write a JAVA program that simulates a vending machine. Users select a product and provide payment. If the payment is sufficient to cover the purchase

Write a JAVA program that simulates a vending machine. Users select a product and provide payment. If the payment is sufficient to cover the purchase price of the product, the product is dispensed and change is given. Otherwise, the payment is returned to the user.

Requirements:

1. Create a class called CashRegister that has methods to totals up sales and computer change due.

2. Create a class called MonetaryUnit that has methods to returns the name of the monetary unit and the monetary value of the unit.

3. Test your designing classes by running the main methods below. public class CashRegisterTester { public static void main(String[] args) { final double NICKEL_VALUE = 0.05; final double DIME_VALUE = 0.1; final double QUARTER_VALUE = 0.25; final double DOLLAR_VALUE = 1.0; CashRegister myRegister = new CashRegister(); myRegister.recordPurchase(1.82); myRegister.enterPayment(1, new MonetaryUnit(DOLLAR_VALUE, "dollar bill")); myRegister.enterPayment(3, new MonetaryUnit(QUARTER_VALUE, "quarter")); myRegister.enterPayment(2, new MonetaryUnit(NICKEL_VALUE, "nickel")); double myChange = myRegister.giveChange(); System.out.println("Change: " + myChange); System.out.println("Expected: 0.03"); } }

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!