CS 1054: Introduction to Programming in JAVA
CS 1054 Introduction to Programming in Java (Spring 2008)
Project 1:
Ice Cream Stations
Instructions
Write an
IceCreamStation class in Java.
An ice cream station sells ice cream cones,
but needs to buy ice cream (by the pint) and
cones (by the box) to make the ice cream cones.
A box of cones contains
20 10 cones and has
a fixed price of $2.50 per box;
a pint of ice cream also has a fixed price of $3.25 per pint.
To make an ice cream cone,
you need a single cone and 1/4 of a pint of ice cream.
The price of an ice cream cone is not fixed and is indicated during a sale.
An ice cream station should be able to monitor its inventory:
how many
cones it has left as well as how much ice cream it has left.
In addition, it should keep track of how many ice cream cones it has sold
so far and how much money it has on hand.
When an ice cream station is created, start it off with $100.00.
You will need to implement the following methods for the IceCreamStation class:
- buyCones: buys cones by the box; number of boxes is indicated as a parameter
- buyIceCream: buys ice cream by the pint; number of pints is indicated as a parameter
- sellIceCreamCones: sells ice cream cones; both the number of ice cream cones
and the unit price are indicated as parameters
- getConesLeft: returns the number of cones left
- getIceCreamLeft: returns the amount of ice cream left (in pints)
- getNumIceCreamConesSold: returns the number of ice cream cones sold
- getCashOnHand: returns the cash the station has on hand (in dollars)
For a more formal description of these methods,
click on this
Java documentation page .
You also need to create an IceCreamStationTester program that tests
your IceCreamStation class.
In this test program,
create one or more IceCreamStation objects and call all methods
of the IceCreamStation class.
Both the IceCreamStation class and the IceCreamStationTester class
should be in a BlueJ project called Project1 .
Document your classes. Include header comments and comments for each method of the class.
Pattern your documentation according to the examples we have used in the lectures and in the labs.
This project is due on February 18 (11:59pm).
Instructions for submitting via Web-Cat
- Go to http://web-cat.cs.vt.edu and click on the "Login to Web-CAT" button in the upper right corner.
- Login with your PID username and password.
- Click on the "Submit" tab in the upper left corner.
- Select the assignment you want to submit and click NEXT.
- Browse to the file you want to upload. Make sure you upload the .java, not the .class file. Also make sure that it’s the actual class, not the tester that you wrote for it (for this project you need to upload the IceCreamStation.java file).
- Click NEXT again and wait while Web-Cat compiles and tests your code.
- If you have points taken off for Style/Coding, click on the IceCreamStation.java link. That will bring up a new screen with comments on the style of your code. Fix them to get full credit.
- Go to the Commenting section of your web-page for a guideline on how to write comments for the class, constructor, and methods.
- If you have points taken off for Correctness/Testing, Web-Cat will give you limited feedback on the bottom of the screen. The most common errors are: logical errors in the code (to fix them go back to BlueJ and make sure that all the methods perform the all tasks that the description calls for), naming the methods something other then what is specified by the instructions, having a method return the wrong type of variable (make sure your if your method has to be "public void" or "public int", etc).
- Click on the "Submit Again" button once you have fixed the errors.