Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions