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

Hello. I am fairly new to programming, and this new assignment has pushed me to

ID: 3548548 • Letter: H

Question

Hello. I am fairly new to programming, and this new assignment has pushed me to my limits. I am almost done with it, I think. Any help is appreciated. Thank you very much. I am having trouble with the bold parts

Design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes to design are:
- ParkedCar class: simulates a parked car
- This class knows the car's make, model, color, license number, and the number of minutes that the car has been parked.
- ParkingMeter Class: simulates a parking meter.
- This classes only responsibility is to know the number of minutes of parking time that has been purchased.
-ParkingTicket class: Simulates a parking ticket
- To report make, model, color, and license number of the illegally parked car.
- To report the amount of the fine which is $25 dollars for the first hour or part of the hour that the car is illegally parked, plus $10 for every additional hour or part of an hour that the car is parked.
- To report the name and badge number of the police officer issuing the ticket.
-PoliceOfficer class: Simulates a police officer
Responsibilities:
- To know the police officer's name and badge number
- To examine a parked car 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.


-My professor wants us to have

+examine(ParkedCar car, ParkingMeter meter): Boolean

+issue(ParkedCar car, ParkingMeter meter): ParkingTicket

(in the issue method, you might need to call the examine method. If it is true, generate a ticket from the ParkingTicket class using the car, the meter, and the police officer himself. If it is false, return null)

within the police officer class and that is really confusing me.


Here is my police officer class



public class PoliceOfficer
{
private String name;
private String badge;

public PoliceOfficer(String name, String badge)
{
this.name = name;
this.badge = badge;
}

public String getName()
{
return name;
}

public String getBadge()
{
return badge;
}

public PoliceOfficer(PoliceOfficer object2)
{
name = object2.name;
badge = object2.badge;
}

//set value for name
public void setName(String name)
{
this.name = name;
}

public void setBadge(String badge)
{
this.badge = badge;
}

public String toString()
{
String str = "Police Officer's Name: " + name + " Badge Number: " + badge;


return str;
}


}


Parked Car Class

public class ParkedCar
{
   private String make;
   private String model;
   private String license;
   private String color;
   private int minutesParked;

   public ParkedCar(String make, String model, String license, String color, int minutesParked)
   {
      this.make = make;
      this.model = model;
      this.license = license;
      this.color = color;
      this.minutesParked = minutesParked;
   }

   public String getMake()
   {
      return make;
   }
   
   public String getModel()
   {
      return model;
   }
   
   public String getLicense()
   {
      return license;
   }
   
   public String getColor()
   {
      return color;
   }

   public int getMinutesParked()
   {
      return minutesParked;
   }
   
   public ParkedCar(ParkedCar object2)
   {
      make = object2.make;
      model = object2.model;
      license = object2.license;
      color = object2.color;
      minutesParked = object2.minutesParked;
   }
   
   public void set(String make, String model, String license, String color, int minutesParked)
   {
      this.make = make;
      this.model = model;
      this.license = license;
      this.color = color;
      this.minutesParked = minutesParked;
   }

   public String toString()
   {
      String str = "Car Make: " + make + " Car Model: " + model + " Car License: " + license +
                   " Car Color: " + color + " Minutes Parked: " + minutesParked;
          
      return str;
   }

}


Parking Meter Class


public class ParkingMeter
{
   private int minutesBought;
   
   public ParkingMeter(int minutesPurchased)
   {
      minutesBought = minutesPurchased;
   }

   public int getMinutesBought()
   {
      return minutesBought;
   }

   public ParkingMeter(ParkingMeter object2)
   {
      minutesBought = object2.minutesBought;
   }

   public void setMinutesBought(int minutesPurchased)
   {
      minutesBought = minutesPurchased;
   }
   
   public String toString()
   {
      String str = "Total minutes purchased on meter: " + minutesBought;
      
      return str;
   }

}


Parking Ticket Class


public class ParkingTicket
{
   private ParkedCar car;
   private ParkingMeter meter;
   private PoliceOfficer office;
   private double fine;

   public ParkingTicket(ParkedCar c, ParkingMeter m, PoliceOfficer o, double fine)
   {
      car = new ParkedCar(c);
      meter = new ParkingMeter(m);
      office = new PoliceOfficer(o);
      this.fine = fine;
   }
   
   public ParkedCar getCar()
   {
      return new ParkedCar(car);
   }

   public ParkingMeter getMeter()
   {
      return new ParkingMeter(meter);
   }

   public PoliceOfficer getOffice()
   {
      return new PoliceOfficer(office);
   }
   public double getFine()
   {
      int minutesExceeded = car.getMinutesParked() - meter.getMinutesBought();
      if(minutesExceeded <= 60)
      {
         fine = 25;
      }
      else
         fine = 25 + (10 * (minutesExceeded/60));
      
      return fine;
   }
   
   public void setFine(double fine)
   {  
      this.fine = fine;
   }

   public String toString()
   {
      String str = "Car's Information: " + car + " Meter's Information: " + meter +
                   " Officier's Information: " + office + "Total Fine: " + fine;
     
      return str;
   }
   
   
}
   
   


Explanation / Answer

All your code is perfect...

I have only added your requirement in bold !

In the PoliceOfficer class, just add these two methods...

Note : PoloceOfficer will only issue the ParkingTicket only when examine is true..


public boolean examine(ParkedCar car, ParkingMeter meter){

int minuteBought = meter.getMinutesBought();

int minuteParked = car.getMinutesParked();

if(minuteParked > minuteBought){

return true;

}else{

return false;

}

}



public ParkingTicket issue(ParkedCar car, ParkingMeter meter){

boolean shallIssueTicket = this.examine(car, meter);

if(shallIssueTicket){

ParkingTicket tkt = new ParkingTicket(car, meter, this, 0.0);

double fine = tkt.getFine();

tkt.setFine(fine);

return tkt;

}

else return null;

}


Please feel free to write back iin case if any issue/concerns...