For this assignment you will design a set of classes that wo
For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes first:
1. The ParkedCar Class: This class should represent a parked car. The class’s responsibilities are as follows:
a. To know the car’s make, model, color, license number, and the number of minutes the car has been parked.
2. The ParkingMeter Class: This class should simulate a parking meter. An Object of ParkedCar will be parked near a ParkingMeter. The ParkedCar will purchase a certain amount of minutes using the parking meter. The class’s only responsibility is as follows:
a. To know the number of minutes of parking time that has been purchased.
3. The ParkingTicket Class: This class should simulate a parking ticket. The class responsibilities are as follows:
a. To report the make, model, color, and license plate number of the illegally parked Car.
b. To report the amount of fine, which is $25 for the first hour or part of an hour that the car has illegally parked, plus $10 for every additional hour or part of an hour that the car is illegally parked.
c. To report the name and badge number of the police officer issuing the ticket.
4. The PoliceOfficer Class: This class should simulate a police officer inspecting parked cars. The class’s responsibilities are as follows:
a. To know the Police Officer’s name and badge number.
b. To examine a ParkedCar Object and a ParkingMeter Object, and determine whether the car’s time has expired.
c. To issue a parking ticket (generate a ParkingTicket Object) if the car’s time has expired.
Generate UML diagram that represent the four classes and the interactions (indicate if it is dependency, aggregation, composition, or association).
Write a demo class “ParkingSimulation” that will demonstrate how these classes interact.
First create an object of a Police Officer (just give the officer a name and badge number).
Read a file (car.txt) that contains information on a list of parked cars along with the parking meter. You should create objects that represent the parked cars and corresponding parking meters and store them in two separate data structures.
The police officer should inspect each parked car and its corresponding meter and issue a parking ticket. If the car is parked legally, no parking ticket is issued.
Display the parking tickets in ascending order of amount of fine.
Keep track of the number of cars that got a parking ticket. Display the count.
Keep track of the total amount of money from all the parking tickets. Display the amount.
An example car.txt file is given below (col1: make, col2: model, col3: license plate, col4: minutes parked, col5: minutes purchased)
Chevrolet
Camaro
RV946
83
120
Kia
Soul
QY229
72
196
Toyota
Camry
PM506
50
126
Ford
Focus
FC938
112
91
Ford
Explorer
BA916
36
171
Ford
Everest
UQ848
57
195
Kia
Sorrento
BW108
55
108
Toyota
Corolla
PD527
103
107
Toyota
Rav4
XS146
68
175
Toyota
Yaris
FY445
103
121
Chevrolet
Spark
QU405
87
144
Chevrolet
Malibu
FT808
37
129
Kia
Optima
CV035
93
170
Kia
Sedona
FT949
67
144
Honda
Civic
QA648
116
91
Honda
Accord
DL815
93
119
Honda
CR-V
BM519
88
125
Mazda
MX-5
XB118
31
143
Mazda
CX-5
VB048
64
108
Subaru
Legacy
XD416
105
153
| Chevrolet | Camaro | RV946 | 83 | 120 |
| Kia | Soul | QY229 | 72 | 196 |
| Toyota | Camry | PM506 | 50 | 126 |
| Ford | Focus | FC938 | 112 | 91 |
| Ford | Explorer | BA916 | 36 | 171 |
| Ford | Everest | UQ848 | 57 | 195 |
| Kia | Sorrento | BW108 | 55 | 108 |
| Toyota | Corolla | PD527 | 103 | 107 |
| Toyota | Rav4 | XS146 | 68 | 175 |
| Toyota | Yaris | FY445 | 103 | 121 |
| Chevrolet | Spark | QU405 | 87 | 144 |
| Chevrolet | Malibu | FT808 | 37 | 129 |
| Kia | Optima | CV035 | 93 | 170 |
| Kia | Sedona | FT949 | 67 | 144 |
| Honda | Civic | QA648 | 116 | 91 |
| Honda | Accord | DL815 | 93 | 119 |
| Honda | CR-V | BM519 | 88 | 125 |
| Mazda | MX-5 | XB118 | 31 | 143 |
| Mazda | CX-5 | VB048 | 64 | 108 |
| Subaru | Legacy | XD416 | 105 | 153 |
Solution
public class Demo
{
public static void main (String[ ] args)
{
// Create a ParkedCar object, passing arguments to the constructor.
ParkedCar myParkedCar = new ParkedCar(\"Chevrolet\", \"Lumina APV\", \"White\", \"556 TNT\", 48);
// Create a ParkingMeter object, passing arguments to the constructor.
ParkingMeter myParkingMeter = new ParkingMeter(48);
// Create a ParkedCar object.
//ParkedCar secondParkedCar = new ParkedCar(\"Chevrolet\", \"Lumina APV\", \"White\", \"556 TNT\",);
//ParkingMeter secondParkingMeter = new ParkingMeter(60);
PoliceOfficer myPoliceOfficer = new PoliceOfficer(\"John Doe\", 1337, myParkedCar, myParkingMeter);
// Create a PoliceOfficer object.
//PoliceOfficer secondPoliceOfficer = new PoliceOfficer(\"John Doe\", 1337, secondParkedCar, secondParkingMeter);
myPoliceOfficer.inspectParkedCar();
ParkingTicket myParkingTicket = new ParkingTicket(myPoliceOfficer.fine, myParkedCar, myParkingMeter);
myParkingTicket.toString();
myParkedCar.toString();
}
}
parked car class
public class ParkedCar
{
private String make; // Car\'s make
private String model; // Car\'s model
private String color; // Car\'s color
private String licenseNumber; public int minutes; // Minutes parked
This constructor initializes the make, model, color, licenseNumber, and minutes fields.
@param pcmake The parked car\'s make.
@param pcmodel The parked car\'s model.
@param pccolor The parked car\'s color.
@param pclnumber The parked car\'s license plate number.
@param pcminutes The number of minutes that the car has been parked.
public ParkedCar(String pcmake, String pcmodel, String pccolor, String pclnumber, int pcminutes)
{
make = pcmake1
model = pcmodel;
color = pccolor;
licenseNumber = pclnumber;
minutes = pcminutes;
}
@param pcmake The parked car\'s make.
@param pcmodel The parked car\'s model.
@param pccolor The parked car\'s color.
@param pclnumber The parked car\'s license plate number.
@param pcminutes The number of minutes that the car has been parked.
public void set(String pcmake, String pcmodel, String pccolor, String pclnumber, int pcminutes)
{
make = pcmake;
model = pcmodel;
color = pccolor;
licenseNumber = pclnumber;
minutes = pcminutes;
}
as a copy of another ParkedCar object.
@param object2 The object to copy.
public ParkedCar(ParkedCar object2)
{
make = object2.make;
model = object2.model;
color = object2.color;
licenseNumber = object2.licenseNumber;
minutes = object2.minutes;
}
toString method
@return A string containing the parked car information.
public String toString()
{
String str = \"Parked car\'s make.....................: \" + make +
\"\ Parked car\'s model..................: \" + model +\"\ Parked car\'s color..................: \" + color +
\"\ Parked car\'s license plate number...: \" + licenseNumber +\"\ Minutes that the car has been parked: \" + minutes;
return str;
}
}
parking meter class
public class ParkingMeter
{
public int minutesPurchased;
This constructor initializes the minutesPurchased field.
@param Minutes of parking time purchased.
public ParkingMeter(int pmmpurchased)
{
minutesPurchased = pmmpurchased;
}
The set method sets a value for each field.
public void set(int pmmpurchased)
{
minutesPurchased = pmmpurchased;
}
/** The copy constructor initializes the object
as a copy of another ParkingMeter object.
@param object2 The object to copy.
public ParkingMeter(ParkingMeter object2)
{
minutesPurchased = object2.minutesPurchased;
}
getMinutesPurchased method
@return The number of minutes of parking time that has been purchased.
public int getMintuesPurchased()
{
return minutesPurchased;
}
}
parking ticket class
public class ParkingTicket
{
private double fine; // The amount of the fine.
private ParkedCar parkedcar; //
private ParkingMeter parkingmeter; //
private PoliceOfficer policeofficer; //
This constructor initializes the parkedcar, parkingmeter, and policeofficer fields.
@param parkedcar
@param parkingmeter
@param policeofficer13
public ParkingTicket(double fine, ParkedCar pcar, ParkingMeter pmeter)
{
parkedcar = new ParkedCar(pcar);
parkingmeter = new ParkingMeter(pmeter);
this.fine = fine;
}
toString method
@return A string containing the parking ticket information.
public String toString()
{
String str = \"Illegally parked car info: \" + parkedcar +\"\ Parking meter info:\" + parkingmeter +
\"\ Amount of the fine...: \" + fine;//\"\ Police officer info: \" + policeofficer;
return str;
}
}








