• Java 2 Platform Standard Edition 5.0 API specification
• OpenJDK source code repository for library classes
• Source code from Data structures and problem-solving using Java, third edition
The goal of this assignment is to design, write, and test a Java program that simulates the operation of a vending machine that sells cans of soda.
The interface to the vending machine, from the point of view of the user, will comprise the following components:
In normal operation, the user inserts coins and dollar bills until the amount deposited equals or exceeds the cost of the soda she wants, then presses the button selecting that soda. The vending machine either reports that the item is sold out or drops a can of soda into the beverage receiver. If the amount deposited exceeds the cost of the soda, the machine drops coins making up difference into the change receiver.
At any point, if the user presses the coin-return lever, the machine drops coins equal in value to the amount so far deposited into the change receiver and cancels the purchase attempt.
The machine turns on the exact-change-only light as soon as it determines that it has less than a dollar in change or lacks the appropriate coins to make up the difference between the cost of a soda and the amount deposited. When the exact-change-only light is on, bills are refused and any coins deposited in excess of the cost of the soda are dropped directly into the change receiver.
Define a class for each of these components and supply it with appropriate methods, one for each mode of behavior or interaction that it can perform.
Internally, the vending machine will have a coin box for receiving deposits from the user, a second coin box for the coins it uses to make change, a bill box in which to store the deposited dollar bills, and a stockpile of soda cans of each of the eight kinds.
Define a class for each of these components and supply it with appropriate methods, one for each mode of behavior or interaction that it can perform.
Define a vending-machine class. Each object of this class will have other objects inside it, stored in fields, belonging to the classes defined above. For this assignment, construct the vending machine with a full stockpile of soda cans and a large supply of change in its change box.
Test your class by simulating some transactions: a successful purchase in which the customer receives change back, transaction in which the customer presses the coin-return lever after depositing the full price of the soda, etc. You may want to create an interactive interface that reads in instructions from the terminal window, performs the requested operations on the vending machine, and reports the results.
This assignment will be due on Monday, February 25.