Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this task, you'll practice writing more classes, and you will apply the concept of class aggregation. This programming task is very similar to what
For this task, you'll practice writing more classes, and you will apply the concept of class aggregation.
This programming task is very similar to what you did for Lab so review it for hints and pointers.
The motivation of this programming task is to simulate a police officer issuing a parking ticket. Create
four classes, ParkedCar, ParkingMeter, ParkingTicket, and PoliceOfficer.
The ParkedCar class is meant to hold information about a car's make, model, color, license number,
and the number of minutes that the car has been parked. It has two constructors; the first is a constructor
that takes five arguments, and the second a copy constructor. Look on page and of the
textbook, to review copy constructors.
ParkedCar
make : String
model : String
color : String
licenseNumber : String
minutesParked : int
ParkedCarmk : String, mdel : String, col : String, lic : String, minParked : int
ParkedCarcar : ParkedCar
setter and getter methods, and the toString method, not shown
The ParkingMeter class is meant to hold information about the number of minutes of parking time
that have been purchased.
ParkingMeter
minutesPurchased : int
ParkingMeternumMinPurchased : int
setter and getter methods, and the toString method, not shown
The PoliceOfficer class holds data about the name and badge number of an officer. It has two
constructors; the first is a constructor that takes as input two arguments, and a second that is a copy
constructor. The class method patrol looks at the number of minutes a car has been parked and the
number of minutes purchased. If the minutes parked are greater than the minutes purchased, a
ParkingTicket object is created and returned; otherwise patrol returns null.
PoliceOfficer
name : String
badgeNumber : String
PoliceOfficerofficeName : String, badgeNumber : String
PoliceOfficerofficer : PoliceOfficer
patrolcar : ParkedCar, meter : ParkingMeter : ParkingTicket
setter and getter methods, and the toString method, not shown
The ParkingTicket class is an aggregate class; it contains instance fields that are reference
variables to ParkedCar and PoliceOfficer objects. The first constructor takes three
arguments, and the second is a copy constructor. The method calculateFine calculates the
amount of a parking fine, which is $ for the first hour or part of an hour that the car is parked
illegally, plus $ for every additional hour or part of an hour that the car is illegally parked. The
toString method should invoke the toString methods of the car and officer fields, and output
the fines details.
ParkingTicket
car : ParkedCar
officer : PoliceOfficer
fine : double
minutes : int
BASEFINE : double
HOURLYFINE : double
ParkingTicketaCar : ParkedCar, anOfficer : PoliceOfficer, meterMins : int
ParkingTicketticket : ParkingTicket
calculateFine : void
setter and getter methods, and the toString method, not shown
In addition to writing the four classes, write a single class, PatrolSimulation, with a main
routine that demonstrates the use of the four classes. The pseudocode for the main routine is shown in
the below box.
Create an array of Car objects, with various minutesParked
values
Create an array of ParkingMeter objects, with minutes so that
the first Car object is in violation, while the second is not
Create an array of ParkingTicket objects
Create a PoliceOfficer object. Give the officer a name and badge
number
Have the officer patrol each of the Car and ParkingMeter object
combinations index i for the array of Car objects should be
matched with index i for the array of ParkingMeter objects, which
should be matched with index i of the array of ParkingTicket
objects
After the PoliceOfficer has patrolled the cars and parking
meters, walk over the array of ParkingTickets and invoke the
toString method if a ticket has been issued, otherwise indicate
that a ticket has not been issued
Refer to the rubric posted on the course website for details about point accrual. A sample invocation of
the program is shown below.
CarParking Meter :
Car Data
Make: Volkswagen
Model:
Color: Red
License Number: RHZM
Minutes Parked:
Officer Data:
Name: Joe Friday
BadgeNumber:
Ticket Data
Minutes Illegally Parked:
Fine: $
CarParking Meter :
No violation
CarParking Meter :
No violation
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started