For this assignment you will design a set of classes that work together to simul
ID: 3810329 • Letter: F
Question
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:
The ParkedCar Class: This class should represent a parked car. The class’s responsibilities are as follows:
To know the car’s make, model, color, license number, and the number of minutes the car has been parked.
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:
To know the number of minutes of parking time that has been purchased.
The ParkingTicket Class: This class should simulate a parking ticket. The class responsibilities are as follows:
To report the make, model, color, and license plate number of the illegally parked Car.
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.
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 class’s responsibilities are as follows:
To know the Police Officer’s name and badge number.
To examine a ParkedCar Object and a ParkingMeter Object, and determine whether the car’s time has expired.
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
Explanation / Answer
#include <iostream>
#include <cmath>
using namespace std;
class ParkedCar
{
string make;
string model;
string color;
string licenseNumber;
int minutesParked;
public:
ParkedCar()
{
make = "Ford";
model = "Figo";
color = "Red";
licenseNumber = "TX041234";
minutesParked = 0;
}
void setMake(string m) { make = m; }
void setModel(string m) { model = m; }
void setColor(string c) { color = c; }
void setLicenseNumber(string l) { licenseNumber = l; }
void setMinutesParked(int n) { minutesParked = n; }
string getMake() { return make; }
string getModel() { return model; }
string getColor() { return color; }
string getLicenseNumber() { return licenseNumber; }
int getMinutesParked() { return minutesParked; }
};
class ParkingMeter
{
ParkedCar pc;
int minutesPurchased;
public:
ParkingMeter(ParkedCar car, int minutes)
{
pc = car;
minutesPurchased = minutes;
}
void setMinutesPurchased(int m) { minutesPurchased = m; }
int getMinutesPurchased() { return minutesPurchased; }
void setParkedCar(ParkedCar p) { pc = p; }
ParkedCar getParkedCar() { return pc; }
};
class PoliceOfficer
{
string policeName;
int badgeNumber;
public:
PoliceOfficer(string name, int num)
{
policeName = name;
badgeNumber = num;
}
void setPoliceName(string name) { policeName = name; }
void setBadgeNumber(int num) { badgeNumber = num; }
string getPoliceName() { return policeName; }
int getBadgeNumber() {return badgeNumber; }
ParkingTicket examineCarMeter(ParkingMeter parkingMeter)
{
ParkedCar pc = parkingMeter.getParkedCar();
int x = parkingMeter.pc.getMinutesParked() - parkingMeter.getMinutesPurchased();
if(x > 0)
{
ParkingTicket pTicket (pc, this, x);
}
else
{
cout<<"Parking Ticket not required."<<endl;
}
}
};
class ParkingTicket
{
ParkedCar car;
PoliceOfficer police;
int fineMinutes;
public:
ParkingTicket(ParkedCar pc, PoliceOfficer po, int min)
{
car = pc;
police = po;
fineMinutes = min;
}
int calculateFineAmount()
{
if(fineMinutes <= 60)
return 25;
else
{
return 25 + ceil((fineMinutes - 60)/60.0) * 10;
}
}
};
int main()
{
ParkedCar p;
ParkingMeter pm (p, 10);
PoliceOfficer po ("Kumar", 222);
po.examineCarMeter (pm);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.