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

THIS NEEDS TO BE DONE IN NETBEANS!! You will NOT have a working program yet. You

ID: 3810681 • Letter: T

Question

THIS NEEDS TO BE DONE IN NETBEANS!!

You will NOT have a working program yet. You will have created five .jave files, including a MainClass, as usual, which will essentially be empty.

    PTS_MainClass

    ParkingMeter

    PoliceOfficer

    ParkedCar

    ParkingTicket


For this you will design a set of classes that work together to simulate a police officer issuing a parking ticket.

The ParkedCar Class: This class should simulate a parked car. The responsibilities of this class are to record the make, model, color, and license number of the car, along with the number of minutes that the car has been parked. The following is a UML class diagram of the class to be developed:




The ParkingMeter Class: This class should simulate a parking meter. The only responsibility of this class is to record the number of minutes purchased. The following is a UML class diagram of the class to be developed:



The ParkingTicket Class: This class should simulate a parking ticket. The class responsibilities are:


- To record the make, model, color, and license number of an illegally parked car.
- To record the amount of the fine, which is $25 for the first hour (i.e., any part of the first hour that the car is illegally parked), plus $10 for every additional full or partial hour the the car is illegally parked.
- To record the name and badge number of the police officer issuing the ticket.

The following is a UML class diagram of the class to be developed. The ParkedCar and PoliceOfficer classes have a relationship to the ParkingTicket class, so they are also shown:


  

The PoliceOfficer Class: This class should simulate a police officer inspecting parked cars. The responsibilities of the class are as follows:


- To record the police officer’s name and badge number.
- To examine a ParkedCar object and a ParkingMeter object, and determine whether the parking time of the car has expired.
- To issue a parking ticket—generate a ParkingTicket object—if the time of the car has expired.

The following is a UML figure that shows the relationship for each object:

Explanation / Answer

Here is the code for ParkedCar.java:

class ParkedCar
{
String make;
String model;
String color;
String licenseNumber;
int minutesParked;
public ParkedCar(String make, String model, String color, String lNum, int mins)
{
this.make = make;
this.model = model;
this.color = color;
licenseNumber = lNum;
minutesParked = mins;
}
public ParkedCar(ParkedCar pc)
{
this.make = pc.make;
this.model = pc.model;
this.color = pc.color;
this.licenseNumber = pc.licenseNumber;
this.minutesParked = pc.minutesParked;
}
public void setMake(String m)         { make = m; }
public void setModel(String m)            { model = m; }
public void setColor(String c)           { color = c; }
public void setLicenseNumber(String l)   { licenseNumber = l; }
public void setMinutesParked(int n)       { minutesParked = n; }
public String getMake()                   { return make; }
public String getModel()               { return model; }
public String getColor()               { return color; }
public String getLicenseNumber()       { return licenseNumber; }
public int getMinutesParked()           { return minutesParked; }
}

ParkingMeter.java:

class ParkingMeter
{
ParkedCar pc;
int minutesPurchased;
  
public ParkingMeter(ParkedCar car, int minutes)
{
pc = new ParkedCar(car);
minutesPurchased = minutes;
}
public void setMinutesPurchased(int m)   { minutesPurchased = m; }
public int getMinutesPurchased()       { return minutesPurchased; }
public void setParkedCar(ParkedCar p) { pc = p; }
public ParkedCar getParkedCar()        { return pc; }
}

ParkingTicket.java:

class ParkingTicket
{
ParkedCar car;
PoliceOfficer police;
int        fineMinutes;
public ParkingTicket(ParkedCar pc, PoliceOfficer po, int min)
{
car = pc;
police = po;
fineMinutes = min;
}
public int calculateFineAmount()
{
if(fineMinutes <= 60)
return 25;
else
{
return 25 + (int)Math.ceil((fineMinutes - 60)/60.0) * 10;
}
}
}

PoliceOfficer.java:

class PoliceOfficer
{
String policeName;
int badgeNumber;
public PoliceOfficer(String name, int num)
{
policeName = name;
badgeNumber = num;
}
public void setPoliceName(String name)   { policeName = name; }
public void setBadgeNumber(int num)       { badgeNumber = num; }
public String getPoliceName()           { return policeName; }
public int getBadgeNumber()               {return badgeNumber; }
public ParkingTicket examineCarMeter(ParkingMeter parkingMeter)
{
ParkedCar pc = parkingMeter.getParkedCar();
int x = parkingMeter.pc.getMinutesParked() - parkingMeter.getMinutesPurchased();
if(x > 0)
{
ParkingTicket pTicket = new ParkingTicket(pc, this, x);
return pTicket;
}
else
{
System.out.println("Parking Ticket not required.");
return null;
}
}
}