Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a set of classes that work together to simulate a police officer issuing

ID: 3630789 • Letter: D

Question

Design a set of classes that work together to simulate a police officer issuing a parking ticket.

1)The ParkedCar Class: This class should simulate 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 that the car has been parked.

2)The ParkingMeter Class: This class should simulate a parking meter. The class's only responsibility is as follows:
-To knwo the number of minutes of parking time that has been purchased.

3)The ParkingTicket Class: This class should simulate a parking ticket. The class's responsibilites are as follows:
-To report the make, model, color, and license number of the illegally parked car
-To report the amount of the fine, which is $25 for the first hour or part of an hour that the car is 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

4)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

Explanation / Answer

//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; // Car's alphanumeric license number public int minutes; // Minutes parked //@param prkcarmake The parked car's make.@param prkcarmodel The parked car's model.@param prkcarcolor The parked car's color.@param prkcarliscnumber The parked car's license plate number.@param prkcarminutes The number of minutes that the car has been parked. */ public ParkedCar(String prkcarmake, String prkcarmodel, String prkcarcolor, String prkcarliscnumber, int prkcarminutes) { make = prkcarmake; model = prkcarmodel; color = prkcarcolor; licenseNumber = prkcarliscnumber; minutes = prkcarminutes; } //@param prkcarmake The parked car's make.@param prkcarmodel The parked car's model.@param prkcarcolor The parked car's color.@param prkcarliscnumber The parked car's license plate number.@param prkcarminutes The number of minutes that the car has been parked. public void set(String prkcarmake, String prkcarmodel, String prkcarcolor, String prkcarliscnumber, int prkcarminutes) { make = prkcarmake; model = prkcarmodel; color = prkcarcolor; licenseNumber = prkcarliscnumber; minutes = prkcarminutes; } 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() { // Create a string representing the object. 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 the string. return str; } } public class ParkingMeter { public int minutesPurchased; // The number of minutes of parking time that has been purchased //This constructor initializes the minutesPurchased field.@param Minutes of parking time purchased. public ParkingMeter(int parkmetminspurchased) { minutesPurchased = parkmetminspurchased; } //The set method sets a value for each field.@param Minutes of parking time purchased. public void set(int parkmetminspurchased) { minutesPurchased = parkmetminspurchased; } //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; } } 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 policeofficer public ParkingTicket(double fine, ParkedCar pcar, ParkingMeter pmeter) { // Create a new ParkedCar object, passing //pcar as an argument to the copy constructor. parkedcar = new ParkedCar(pcar); // Create a new ParkingMeter object, passing //pmeter as an argument to the copy constructor. parkingmeter = new ParkingMeter(pmeter); // Create a new PoliceOfficer object, passing // pofficer as an argument to the copy constructor. policeofficer = new PoliceOfficer(o); this.fine = fine; } //toString method @return A string containing the parking ticket information. public String toString() { // Create a string representing the object. String str = "Illegally parked car info: " + parkedcar +" Parking meter info:" + parkingmeter +" Amount of the fine...: " + fine +" Police officer info: " + policeofficer; // Return the string. return str; } } public class PoliceOfficer { private String name; // Name private int badgeNumber; // Badge number private ParkedCar parkedcar; // Initialize "parkedcar" object to be copied private ParkingMeter parkingmeter; // Initialize "parkingmeter" object to be copied private ParkingTicket parkingticket; // public double fine = 0; // //This constructor initializes the name and badgeNumber fields.@param poloffname The police officer's name. @param pobnumber The police officer's badge number. public PoliceOfficer(String poloffname, int pobnumber, ParkedCar pcar, ParkingMeter pmeter) { name = poloffname; badgeNumber = pobnumber; // Create a new ParkedCar object, passing // pcar as an argument to the copy constructor. parkedcar = new ParkedCar(pcar); // Create a new ParkingMeter object, passing // pmeter as an argument to the copy constructor. parkingmeter = new ParkingMeter(pmeter); } //The set method sets a value for each field.@param poloffname The police officer's name.@param pobnumber The police officer's badge number. public void set(String poloffname, int pobnumber) { name = poloffname; badgeNumber = pobnumber; } //The copy constructor initializes the object as a copy of another PoliceOfficer object.@param object2 The object to copy. public PoliceOfficer(PoliceOfficer object2) { name = object2.name; badgeNumber = object2.badgeNumber; // Create a new ParkedCar object, passing // pcar as an argument to the copy constructor. parkedcar = new ParkedCar(pcar); //Create a new ParkedCar object. parkedcar = new ParkedCar(pcar); //Create a ParkingMeter object. parkingmeter = new ParkingMeter(pmeter); } public ParkedCar getParkedCar() { // Return a copy of the ParkedCar object. return new ParkedCar(parkedcar); } public ParkingMeter getParkingMeter() { // Return a copy of the ParkingMeter object. return new ParkingMeter(parkingmeter); } public void inspectParkedCar() { // Determine whether the car is illegally parked. if (parkedcar.minutes > parkingmeter.minutesPurchased) // Determine the amount of the fine. if (parkedcar.minutes - parkingmeter.minutesPurchased
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote