Answered step by step
Verified Expert Solution
Link Copied!

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 2, 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 518 and 519 of the
textbook, to review copy constructors.
ParkedCar
- make : String
- model : String
- color : String
- licenseNumber : String
- minutesParked : int
+ ParkedCar(mk : String, mdel : String, col : String, lic : String, minParked : int)
+ ParkedCar(car2 : 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
+ ParkingMeter(numMinPurchased : 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
+ PoliceOfficer(officeName : String, badgeNumber : String)
+ PoliceOfficer(officer : PoliceOfficer)
+ patrol(car : 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 $30 for the first hour or part of an hour that the car is parked
illegally, plus $10 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
+ BASE_FINE : double =30.0
+ HOURLY_FINE : double =10.0
+ ParkingTicket(aCar : ParkedCar, anOfficer : PoliceOfficer, meterMins : int)
+ ParkingTicket(ticket : 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 3 Car objects, with various minutesParked
// values
// Create an array of 3 ParkingMeter objects, with minutes so that
// the first Car object is in violation, while the second is not
// Create an array of 3 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.
Car/Parking Meter 1:
Car Data
Make: Volkswagen
Model: 1972
Color: Red
License Number: 147RHZM
Minutes Parked: 121
Officer Data:
Name: Joe Friday
BadgeNumber: 4788
Ticket Data
Minutes Illegally Parked: 61
Fine: $35.00
Car/Parking Meter 2:
No violation
Car/Parking Meter 3:
No violation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions