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

I looked at the textbook solutions for this but I don\'t understand the way that

ID: 3673766 • Letter: I

Question

I looked at the textbook solutions for this but I don't understand the way that solution was done or the other answers already given for this question. Can anyone write a code for this? I am still new.

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:

• 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.
• 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 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
• 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
Write a program that demonstrates how these classes collaborate.

Explanation / Answer

public class ParkingTicketSimulator
{
class ParkedCar
{
private String make;
private String model;
private String color;
private String licenseNumber;
private int minutesParked;
public ParkedCar(String make, String model, String color,
String licenseNumber, int minutesParked)
{
super();
this.make = make;
this.model = model;
this.color = color;
this.licenseNumber = licenseNumber;
this.minutesParked = minutesParked;
}
public String getMake()
{
return make;
}
public void setMake(String make)
{
this.make = make;
}
public String getModel()
{
return model;
}
public void setModel(String model)
{
this.model = model;
}
public String getColor()
{
return color;
}
public void setColor(String color)
{
this.color = color;
}
public String getLicenseNumber()
{
return licenseNumber;
}
public void setLicenseNumber(String licenseNumber)
{
this.licenseNumber = licenseNumber;
}
public int getMinutesParked()
{
return minutesParked;
}
public void setMinutesParked(int minutesParked)
{
this.minutesParked = minutesParked;
}
}

PARKING METER:

class ParkingMeter
{
private int minutesPurchased;
public ParkingMeter(int minutesPurchased)
{
super();
this.minutesPurchased = minutesPurchased;
}
public int getMinutesPurchased()
{
return minutesPurchased;
}
public void setMinutesPurchased(int minutesPurchased)
{
this.minutesPurchased = minutesPurchased;
}
}


class PoliceOfficer
{
private String name;
private String badgeNumber;
public PoliceOfficer(String name, String badgeNumber)
{
super();
this.name = name;
this.badgeNumber = badgeNumber;
}
public ParkingTicket patrol(ParkedCar car, ParkingMeter meter) {
ParkingTicket ticket = null;
int illegalMinutes = car.getMinutesParked()
- meter.getMinutesPurchased();
if (illegalMinutes > 0)
{
ticket = new ParkingTicket(car, this, illegalMinutes);
}
return ticket;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getBadgeNumber()
{
return badgeNumber;
}
public void setBadgeNumber(String badgeNumber)
{
this.badgeNumber = badgeNumber;
}
}

PARKING TICKET CLASS:

class ParkingTicket
{
private ParkedCar car;
private PoliceOfficer officer;
private double fine;
private int minutes;
public final double BASE_FINE = 25.0;
public final double HOURLY_FINE = 10.0;
public ParkingTicket(ParkedCar car, PoliceOfficer officer, int minutes)
{
super();
this.car = car;
this.officer = officer;
this.minutes = minutes;
calculateFine();
}
private void calculateFine()
{
double hours = minutes / 60.0;
int hoursAsInt = (int) hours;
if ((hours - hoursAsInt) > 0)
{
hoursAsInt++;
}
fine = BASE_FINE;
fine += (hoursAsInt * HOURLY_FINE);
}
public ParkedCar getCar()
{
return car;
}
public void setCar(ParkedCar car)
{
this.car = car;
}
public PoliceOfficer getOfficer()
{
return officer;
}
public void setOfficer(PoliceOfficer officer)
{
this.officer = officer;
}
public double getFine()
{
return fine;
}
public void setFine(double fine)
{
this.fine = fine;
}
public int getMinutes()
{
return minutes;
}
public void setMinutes(int minutes)
{
this.minutes = minutes;
}
public String toString()
{
return "ParkingTicket [car=" + car + ", officer=" + officer+ ", fine=" + fine + ", minutes=" + minutes+ ", BASE_FINE=" + BASE_FINE + ", HOURLY_FINE="+ HOURLY_FINE + "]";
}
}
public static void main(String[] args)
{
ParkingTicketSimulator parkingTicketSimulator = new ParkingTicketSimulator();ParkedCar car = parkingTicketSimulator.new ParkedCar("Benz", "2009","Red", "ze123", 250);
ParkingMeter meter = parkingTicketSimulator.new ParkingMeter(60);
PoliceOfficer officer = parkingTicketSimulator.new PoliceOfficer("jckson", "1509");
ParkingTicket ticket = officer.patrol(car, meter);
if (ticket != null)
{
System.out.println(ticket);
}
else
{
System.out.println("No crimes committed!");
}
}
}

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