The ParkedCar class - This class should simulate a parked car. The classes respo
ID: 3638869 • Letter: T
Question
The ParkedCar class - This class should simulate a parked car. The classes responsiblities are as follows:-To know the car's make, model, color, license number, and the number of minutes that the car has been parked.
The ParkingMeter class - This class should simulate a 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's responsibilities are as follows:
-To report the make, model, color, and license number of the illegaly 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 illegaly parked, plus $10 for every additional hour or part of an hour that the car is illegaly 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 responsiblities 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 parking ticket object) if the car's time has expired
Explanation / Answer
nice that where you are parking tickets are still handed out by police officers. Round here it is done by nasty parking attendants that are employed by the council to be as ruthless as possible to make the council as much money as they can. Now looking at the attributes of PoliceOfficer we have: 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; // That means, in OO interpretation: A police officer has a name A police officer has a badge number A police officer has a parked car A police officer has a parking meter A police officer has a parking ticket A police officer has a fine (which is publicly accessible). The first two of those sound correct to me but the remainder do not. A police officer may issue a fine, possibly. That is an action not an attribute, therefore it should be possibly implemented as a method of PoliceOfficer. To issue a fine, you would need to pass in as a parameter either a parked car or a parking meter or both. You may be able to determine one from the other (what is currently parked at the meter or where the car is currnetly parked). You would not pass in a parking ticket, because the Police Officer would create that, i.e. it would be a new instance of a class created by the function. The fine (the amount) would probably be an attribute of the parking ticket. With this in mind, I find the ParkedCar class a little odd. Conceptually, it's a Car associated with a number of parked minutes, so I'd be inclined to model it as a class containing a Car or CarDetails object and a minutes variable, but that may be overkill for this example. You've given it a constructor and an identical 'set' method, plus a copy constructor, which implies that a particular ParkedCar instance can change make, model, color, plate and number of minutes parked, or even exactly duplicate another parked car - this makes no sense to me - isn't a particular parked car unique? How can it suddenly become a different parked car? I could understand a ParkingSpace having different cars in it for different times, but not a parked car. In my world, the car part of a parked car doesn't change, but number of minutes parked do change (setMinutesParked' or even 'incrementMinutesParked'). When that car drives away (no longer a ParkedCar), a new ParkedCar takes its place. All this may be splitting hairs, but I don't think that 'set' method is needed or the copy constructor (btw copy constructors in Java are generally a bad idea if subclasses may be involved - use the 'clone' method instead). I feel the same about ParkingMeter having a copy constructor - why would you want to duplicate a ParkingMeter (suppose you decide to add the location and serial number to the ParkingMeter - how could you have 2 meters with the same location and serial number ?). You might conceivably want to set one meter to the same number of minutes on another (although I can't think why), but then surely you'd getMinutes from one and setMinutes on the other? BTW using plain 'set' for the method name isn't very informative. I would recommend 'setMinutes' or even 'setMinutesParked'. Finally, when you create a new parking meter, how can the minutes be anything other than zero? Do you really need to pass a value to the constructor if you have a 'setMinutes' method? This, of course depends on how 'real' you want the simulation to be - but a simulation should bear some resemblance to the real world or it's not a simulation of it... It's debatable whether a ParkingTicket should contain a ParkedCar, a ParkingMeter and a PoliceOfficer... it should hold the relevant car details, number of minutes and relevant police officer details, but the objects themselves? I don't like it, but it's a matter of taste, and it depends how 'real' the simulation is supposed to be - see above. The parking ticket should definitely not be initialized with the fine. The ticket is created by a police officer, but he doesn't know (or care) what the fine is, he just copies information from meter and car. If the ticket must report the amount of the fine, the ticket should calculate it. The ticket can store the hourly rate details and calculate the fine when asked (this would normally be done by an office clerk somewhere but we don't have one). The PoliceOfficer is also odd... Do you have to have a parked car and a parking meter before you can create a police officer???? I say no. The car and meter are external objects. A PoliceOfficer has a name and number. That's it. The officer looks at a parked car and the meter, and issues a ticket if required. He can do this many times with many cars and meters. There are a number of ways to approach this, but basically, it will involve a method that takes a ParkedCar and ParkingMeter, and decides whether to issue a ticket. For simplicity, you could make it all one method, which returns a ticket or null. Again, it makes no sense to have a copy constructor for a PoliceOfficer - there can only be one PoliceOfficer with that name and number.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.