CS 1054 Introduction to Programming in Java (Spring 2008)
Project 2:
Ice Cream Stations (Version 2)
Instructions
-
Rewrite your IceCreamStation class so that it now guards against insufficient cash
or ingredients during its buy and sell actions. In addition, arrange it
so that IceCreamStation objects can be created with varying initial cash.
In particular,
-
Create an additional constructor with a parameter
that indicates the starting cash on hand for the station:
public IceCreamStation( double startCash ).
-
Use conditional statements in the appropriate methods
to guard against not having enough cash when buying cones or ice cream.
If there isn’t enough cash available,
make sure that no ingredients are bought and
that the method prints a statement to indicate the problem
(e.g. "Not enough cash to buy ice cream",
or "Not enough cash to buy cones").
-
Use conditional statements in the appropriate method to guard
against not having enough of either ingredient when selling ice cream cones.
If there isn’t enough ice cream or cones, make sure that no ice cream cones
are sold and that the method prints appropriate statements
(e.g. "Not enough ice cream", or "Not enough cones";
note: you may print just one of these statements even if both apply).
Here is an
updated Java documentation page
for IceCreamStation.
Important:
For this version, make sure your "magic numbers" (i.e.,
the price of a box of cones, the number of cones per box, the price of a pint
of ice cream, and the amount of ice cream per ice cream cone)
are all declared
as constants (final variables).
- Testing: Write a revised IceCreamTester so you could
test your new and improved methods. For instance, try the following:
- create an IceCreamStation object with 10.00 cash,
buy 5 boxes of cones (this should print an error message),
buy 2.5 pints of ice cream (this should work),
sell 1 ice cream cone, at any price (this should print an error message).
- create another IceCreamStation object (the regular way with 100.00 cash),
buy 10 boxes of cones (this should work),
buy 10 pints of ice cream (this should work),
sell 30 ice cream cones (this should work),
sell 50 ice cream cones (this should print an error message),
buy 100 pints of ice cream (this should print an error message,
unless you sold the 30 ice cream cones at a ridiculous price).
You do not need to submit your tester file.
- Submission: submit IceCreamStation.java through
http://web-cat.cs.vt.edu
as you did before.
This project is due on Monday, March 10 (11:59pm),
but webcat will be accepting submissions as early as Thursday, Feb 28.
Go to the Commenting section of your web-page for a guideline on how to write
comments for the class, constructor, and methods.
- Optional (no submission required).
To prepare you for your next project,
add an IceCreamStationConsole class to
the BlueJ project that contains IceCreamStation;
cut and paste this
code .
Study how this program works.