In: Computer Science
Parking Ticket simulator 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 responsibili-ties 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.
Requirements:
No data must be collected from the user from inside the class constructor or any other methods. Data must be collected outside the class(perhaps in the main) and can be passed into the object through constructors. This applies to Car, ParkingTicket, PoliceOfficer, ParkingMeter and all other classes.
For any constructor, pass only information that is needed to initialize the objects of that class. For example, when you create police officer object, pass only police office information to build the object, not car, or parking meter information.
Output Requirements
File name must be: ParkingCarSimulator.java
Test Case1:
Enter the officer's name
John
Enter officer's badge number
1234
Enter the car's make
Toyota
Enter the car's model
Carolla
Enter the car's color
Purple
Enter the car's liscense number
34RJXYZ
Enter Minutes on car
20
Enter the number of minutes purchased on the meter
15
Car parking time has expired.
Ticket data:
Make: Toyota
Model: Carolla
Color: Purple
Liscense Number: 34RJXYZ
Officer Name: John
Badge Number: 1234
Fine: 25.0
Test Case 2( No Ticket Generated)
Enter the officer's name
Susan
Enter officer's badge number
455454
Enter the car's make
BMW
Enter the car's model
E300
Enter the car's color
White
Enter the car's liscense number
CA3433
Enter Minutes on car
45
Enter the number of minutes purchased on the meter
60
The car parking minutes are valid
Test Case 3( Validate input data)
Enter the officer's name
Adam
Enter officer's badge number
34343
Enter the car's make
Ford
Enter the car's model
Model5
Enter the car's color
Green
Enter the car's liscense number
CA55443
Enter Minutes on car
-12
Invalid Entry. Please try again.
20
Enter the number of minutes purchased on the meter
0
Invalid Entry. Please try again.
-20
Invalid Entry. Please try again.
15
Car parking time has expired.
Ticket data:
Make: Ford
Model: Model5
Color: Green
Liscense Number: CA55443
Officer Name: Adam
Badge Number: 34343
Fine: 25.0
ParkedCar.java (code screenshot)
ParkingMeter.java (Program code screenshot)
ParkingTicket.java (Program code screenshot)
PoliceOfficer.java (Program code screenshot)
ParkingCarSimulator.java (Program code screenshot)
Sample Output Screenshot
Program (Code to copy)
ParkedCar.java
package app;
public class ParkedCar {
private String make;
private String model;
private String color;
private String licenseNo;
private int minutesParked;
public String getMake() {
return this.make;
}
public void setMake(String make) {
this.make = make;
}
public String getModel() {
return this.model;
}
public void setModel(String model) {
this.model = model;
}
public String getColor() {
return this.color;
}
public void setColor(String color) {
this.color = color;
}
public String getLicenseNo() {
return this.licenseNo;
}
public void setLicenseNo(String licenseNo) {
this.licenseNo = licenseNo;
}
public int getMinutesParked() {
return this.minutesParked;
}
public void setMinutesParked(int minutesParked) {
this.minutesParked = minutesParked;
}
public ParkedCar(String make, String model, String color, String licenseNo, int minutesParked) {
this.make = make;
this.model = model;
this.color = color;
this.licenseNo = licenseNo;
this.minutesParked = minutesParked;
}
}
ParkingMeter.java
package app;
public class ParkingMeter {
private int timePurchased;
public int getTimePurchased() {
return this.timePurchased;
}
public void setTimePurchased(int timePurchased) {
this.timePurchased = timePurchased;
}
public ParkingMeter(int timePurchased){
this.timePurchased=timePurchased;
}
}
ParkingTicket.java
package app;
public class ParkingTicket {
private ParkedCar car;
private ParkingMeter meter;
private PoliceOfficer officer;
float fine;
boolean isValidParkingMinutes;
public ParkingTicket(ParkedCar car, ParkingMeter meter, PoliceOfficer officer){
this.car=car;
this.meter=meter;
this.officer=officer;
//calculate fine
int illegalMinutes = car.getMinutesParked()-meter.getTimePurchased();
if(illegalMinutes<=60){
fine=25;
}else{
illegalMinutes-=60;
fine=25;
int additionalHours = illegalMinutes/60;
//add 1 to additional hourse if part of additional hours is there
additionalHours+=(illegalMinutes%60 == 0 ? 0 : 1);
fine=fine+additionalHours*10;
}
}
public String toString(){
return "Make: "+car.getMake()+"\nModel: "+car.getModel()+"\nColor: "+
car.getModel()+"\nLicense Number: "+car.getLicenseNo()+
"\nOfficer Name: "+officer.getName()+"\nBadge Number: "+officer.getBadgeNo()+
"\nFine: $"+fine+"\n";
}
}
PoliceOfficer.java
package app;
public class PoliceOfficer {
private String name;
private int badgeNo;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public int getBadgeNo() {
return this.badgeNo;
}
public void setBadgeNo(int badgeNo) {
this.badgeNo = badgeNo;
}
public PoliceOfficer(String name, int badgeNo){
this.name=name;
this.badgeNo=badgeNo;
}
public boolean examine(ParkedCar car, ParkingMeter meter){
//check if car time has expired
if(car.getMinutesParked()>meter.getTimePurchased()){
//car time has expired
//generate a parking ticket
ParkingTicket ticket = new ParkingTicket(car, meter, this);
System.out.println("Car parking time has expired.\nTicket data:");
System.out.println(ticket);
return true;
}else{
System.out.println("The car parking minutes are valid.");
return false;
}
}
}
ParkingCarSimulator.java
package app;
import java.util.*;
public class ParkingCarSimulator {
public static void main(String[] args) {
//declare variables to read from user
String officerName;
int officerBadgeNo;
String carMake;
String model;
String color;
int minutesOnCar;
String licenseNo;
int minutesPurchased;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the officer's name");
officerName=sc.next();
System.out.println("Enter officer's badge number");
officerBadgeNo=sc.nextInt();
System.out.println("Enter the car's make");
carMake=sc.next();
System.out.println("Enter the car's model");
model=sc.next();
System.out.println("Enter the car's color");
color=sc.next();
System.out.println("Enter the car's liscense number");
licenseNo=sc.next();
System.out.println("Enter Minutes on car");
minutesOnCar=sc.nextInt();
//validate data
while(minutesOnCar<=0){
System.out.println("Invalid Entry. Please try again.");
minutesOnCar=sc.nextInt();
}
System.out.println("Enter the number of minutes purchased on the meter");
minutesPurchased=sc.nextInt();
//validate data
while(minutesPurchased<=0){
System.out.println("Invalid Entry. Please try again.");
minutesPurchased=sc.nextInt();
}
//create PoliceOfficer object
PoliceOfficer officer = new PoliceOfficer(officerName, officerBadgeNo);
//create ParkedCar object
ParkedCar car= new ParkedCar(carMake, model, color, licenseNo, minutesOnCar);
//create ParkingMeter object
ParkingMeter meter = new ParkingMeter(minutesPurchased);
//do examination
officer.examine(car, meter);
}
}