ITEC 120 Back to Assignment index page
   
Program 3 - Parking meter
Submit your program files in a folder called RU03 in your directory on neelix.

Description:  Write a class and a driver program that simulates a parking meter.

When you make a new parking meter, it contains no coins and has no time on it. You can then insert a nickel for 5 minutes, a dime for 12 minutes, or a quarter for 30 minutes. The parking meter can only go up to 2 hours. You can also show the contents of the parking meter or simulate the passing of time. There is also a method which simply prints the instructions for the use of the meter. The toString method will return a nicely formatted string which shows the time available on the parking meter. Here's a UML class diagram for ParkingMeter:

ParkingMeter
- nickels, dimes, quarters: int
- time : int
+ ParkingMeter()
+ insertNickel() : void
+ insertDime() : void
+ insertQuarter() : void
+ timePasses( minutes : int ) : void
+ instructions() : void
+ showContents() : void
+ toString() : String

Write a driver called program3.java which lets the user choose to insert a coin in the meter, simulate the passing of time, show the contents of the meter (that is, how much money is in there), or exit the program.

When you run program3.java, it outputs:

Program Outputs Insert a nickel for 5 minutes
Insert a dime for 12 minutes
Insert a quarter for 30 minutes
for a max time of 2 hours


What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit
User Inputs s
Program Outputs The meter contains:
     0 Quarters
     0 Dimes
     0 Nickels
That is 0 dollars and 0 cents


What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit
User Inputs N
Program Outputs

5 mins

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs d
Program Outputs

17 mins

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs Q
Program Outputs

47 mins

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs q
Program Outputs 1 hour and 17 mins

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs Q
Program Outputs 1 hour and 47 mins

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs Q
Program Outputs

2 hours

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs Q
Program Outputs

2 hours

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs s
Program Outputs

The meter contains:
     5 Quarters
     1 Dime
     1 Nickel
That is 1 dollar and 40 cents

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs T
Program Outputs How many minutes?
User Inputs 100
Program Outputs

20 mins

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs t
Program Outputs How many minutes?
User Inputs 30
Program Outputs

The meter is expired.

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs d
Program Outputs

12 mins

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs S
Program Outputs The meter contains:
     5 Quarters
     2 Dimes
     1 Nickel
That is 1 dollar and 50 cents

What would you like to do ?

N - Insert a Nickel
D - Insert a Dime
Q - Insert a Quarter
S - Show contents of meter
T - Time passes
E - Exit

User Inputs E

TURNING IN YOUR PROGRAM: You will turn in two files. You'll have the driver program, named program3.java, and the ParkingMeter class, named ParkingMeter.java. Submit both files to neelix in a folder called RU03 in your folder.