Ryerson University, Department of Computer Science
Computer Science II
Assignment 1: Object Oriented Programming and GUIs
To practice using interfaces, event listeners, graphical
components, and subclasses by implementing
a simulation of a vending machine. Modify the code
from Horstmann's Big Java Chap. 12 so that the interface looks something like
the screen capture below.
Date Posted: Mon. Jan. 31, 2005
Due Date: Mon. Feb. 28, 2005
Pair programming: You can do the assignment in pairs or alone.
The user interface works as follows from top to bottom, left to right:
Your application should include the following classes:
- The label shows the image of the current choice of product
that the user can buy.
- The combo box allows selection of the various products.
- The restock button allows the administrator to restock
the machine. It first causes a dialog box to appear requesting
the password. If the password is entered correctly, then the
total sales thus far is shown in another dialog box, and the
machine is restocked with products.
- The text field to the right of the Tender label is where the
user types in how much money is being inserted.
- The Buy button causes the sale to occur provided that the
tendered money is sufficient. The change is shown in the
- VendingTest which has a main method to create the frame
- VendingFrame which creates a vending machine and the
- VendingMachine which holds the products as an array list
and keeps track of total sales and can be restocked.
- Product which holds product information, such as
name, price, and icon of a product
- Beverage which is a subclass specialization of
Product. The primary difference is that the beverage
indicates the type of sweetener used.