CS 1054 Introduction to Programming in Java (Spring 2008)
Project 4:
Grocery Operations
Instructions
For this project,
you will write classes that simulate activities in a grocery.
We can view a grocery as an aggregate of the items that it sells.
Activities that need to be simulated include:
- adding an item to be carried in the grocery
- recieving a shipment for an item (stocking up)
- selling items
- checking how much stock is left for one or all of the items
- checking how much cash the grocery has on hand
There will be four
classes in your BlueJ project:
- Item
represents an item to be carried in a grocery.
Item objects should store its name (e.g., "butter"),
unit name (e.g., "sticks"), buying price,
selling price, and current stock level.
Consult the documentation page
for details on the constuctor and methods for this class.
- Grocery
represents the grocery object and should store
an array or array list of items,
and cash on hand for the grocery.
When a grocery is created,
it is given initial cash on hand (provided through the constructor)
with no items carried yet.
Operations performed on the Grocery oject eventually
interacts with the corresponding project object.
For example,
when an item is sold,
the selling price of the corresponding item object is accessed
(so that cash on hand can be updated correctly)
and then the stock level of that item is reduced.
Consult the documentation page
for details on the constuctor and methods for this class.
- GroceryTester: Creates a Grocery object
and tests methods of that class.
This code is provided for you.
Just create the class in BlueJ and
cut and paste this
text.
When it executes,
the following output should result.
- GroceryConsole: Creates a Grocery object
and prompts a user for activities to be carried out
on the grocery.
Begin by prompting for initial cash on hand amount,
and proceed with a loop that repeatedly
asks and carries out activities in the grocery.
Submission: Zip all three java programs you created
(Item, Grocery, GroceryConsole)
and submit through
http://web-cat.cs.vt.edu
as you did before.
This project is due on Saturday, April 26 (11:59pm),
and webcat will begin accepting submissions by April 18.
Your grade will depend on the correctness of your letter classes
and the console program and compliance with coding style guidelines
as indicated in
Commenting .