You are on page 1of 4

CS 141-02

Programming Project 2
Due: Wednesday, 7/9/2014, 11:59 PM
Important: Please read this document completely before you start coding. Also, please read
the submission instructions carefully before submitting the project. For code organization
purpose, you should create a CS141 folder in your ZFS. Inside the CS141 folder, create
another folder named Project2 that will contain the programs that you write for this project.
Please see the Lab 1 handout for a list of useful UNIX commands.
Objective:
To be able to use objects made up of other objects (Aggregation)
To be able to write a copy constructor
To be able to write equals and toString methods
To be able to write methods that pass and return objects

Parking Ticket Simulator
For this assignment you will design a set of classes that work together to simulate a police
officer issuing a parking ticket. Please note, due to space constraints, some UML diagrams omit
getter and setter methods. But you may need to write those methods as appropriate in you
java classes. You should design the following classes:
The ParkingMeter Class: This class should simulate a parking meter. The classs
only responsibility is as follows:
o To know the number of minutes of parking time that has been purchased.

The ParkedCar Class: This class should simulate a parked car. The classs
responsibilities are as follows:
o To know the cars make, model, color, license number, and the number of
minutes that the car has been parked.

The ParkingTicket Class: This class should simulate a parking ticket. The classs
responsibilities are as follows:
o To report the make, model, color, and license number of the illegally parked car
o To report the amount of the fine, which is $25 for the base fine when the car is
illegally parked, plus $10 for every hour or part of an hour that the car is illegally
parked (example: with a 60 minute parking permit purchased, if a car was found
parked for a total of 125 minutes, $25 base fine + $20 for 65 min illegal parking)
o To report the name and badge number of the police officer issuing the ticket
The PoliceOfficer Class: This class should simulate a police officer inspecting
parked cars. The classs responsibilities are as follows:
o To know the police officers name and badge number
o To examine a ParkedCar object and a ParkingMeter object, and determine
whether the cars time has expired
o To issue a parking ticket (generate a ParkingTicket object) if the cars time has
expired
You have to use the following driver program to demonstrate how these classes collaborate.
/**
Driver program
Parking Ticket Simulator.
*/

public class ParkingTicketSimulator
{
public static void main(String[] args)
{
// Create a ParkedCar object.
// The car was parked for 125 minutes.
ParkedCar car = new ParkedCar("Volkswagen", "1972", "Red", "147RHZM", 125);

//Uncomment the following statement to demonstrate No crimes
committed
//ParkedCar car = new ParkedCar("Volkswagen", "1972", "Red", "147RHZM", 60);


// Create a ParkingMeter object. 60 minutes were purchased.
ParkingMeter meter = new ParkingMeter(60);

// Create a PoliceOfficer object.
PoliceOfficer officer = new PoliceOfficer("Joe Friday", "4788");

// Let the officer patrol.
ParkingTicket ticket = officer.patrol(car, meter);

// Did the officer issue a ticket?
if (ticket != null)
System.out.println(ticket);
else
System.out.println("No crimes committed!");
}
}

Sample Output:
** With the car object parked for 125 mins

Car Data:
Make: Volkswagen
Model: 1972
Color: Red
License Number: 147RHZM
Minutes Parked: 125
Officer Data:
Name: Joe Friday
BadgeNumber: 4788
Minutes Illegally Parked: 65
Fine: $45.00

**With the car object parked for 60 mins
No crimes committed!

Submission direction:
Your java programs must contain the following information at the top of each file:
//Your name
//CS141-02
//Project 2 ParkingTicketSimulator
//Date
Before submission, make sure your program compiles and runs correctly on ZFS java compiler.
Once you are satisfied testing the execution of the program, you need to use the script
command to record the command line display showing your program output. Please follow the
steps described below to prepare the submission file:
1. Inside your Project2 folder, on the terminal, type in the command: script
project2.txt
2. Compile and run your program to display the output similar to the sample output.
3. Exit the script by typing in: exit
4. Submit project2.txt as well as all the .java files as an
attachment using the Blackboard, under the Programming Projects folder, Project 2
assignment.
Late submission policy: As mentioned in the syllabus: Late programming projects will not be
accepted. In case if you cannot complete a project by the due date, submit whatever you have
completed for partial credit.

You might also like