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

Project: Parking Ticket Simulator Problem Description: For this assignment you w

ID: 3628884 • Letter: P

Question

Project: Parking Ticket Simulator
Problem Description:
For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes you should design are:
• The ParkedCar Class: This class should simulate a parked car. The class’s responsibili-ties are:
a. 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:
a. 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:
a. To report the make, model, color, and license number of the illegally parked car
b. 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
c. 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:
a. To know the police officer’s name and badge number
b. To examine a ParkedCar object and a ParkingMeter object, and determine whether the car’s time has expired
c. To issue a parking ticket ( generate a ParkingTicket object) if the car’s time has expired
Write a program that demonstrate how these classes collaborate

Explanation / Answer

import java.io.*;

import java.util.*;

//class ParkedCar

class ParkedCar

{

String make;

String model;

String color;

int licenceNumber;

int minutes;

public ParkedCar()

{

}

public ParkedCar(String make,String model,String color,int lnumber,int minutes)

{

make=make;

model=model;

color=color;

licenceNumber=lnumber;

minutes=minutes;

}

public void setMake(String m)

{

make=m;

}

public void setModel(String m)

{

model=m;

}

public void setColor(String c)

{

color=c;

}

public void setLicence(int ln)

{

licenceNumber=ln;

}

public void setMinutes(int m)

{

minutes=m;

}

public String getMake()

{

return(make);

}

public String getModel()

{

return(model);

}

public String getColor()

{

return(color);

}

public int getLicence()

{

return(licenceNumber);

}

public int getMinutes()

{

return(minutes);

}

}

//class Parking Meter

class ParkingMeter

{

int minPurchased;

public ParkingMeter(int mp)

{

minPurchased=mp;

}

public int getMinutesPurchased()

{

return(minPurchased);

}

}

//class ParkingTicket

class ParkingTicket

{

int extraTime;

public ParkingTicket(){}

public void generateTicket(ParkedCar pc,int time)

{

extraTime=pc.getMinutes()-time;

extraTime=extraTime+extraTime%60;

extraTime=extraTime/60;

System.out.println("Car Details");

System.out.println("Make "+pc.getMake());

System.out.println("Model "+pc.getModel());

System.out.println("Color "+pc.getColor());

System.out.println("License number "+pc.getLicence());

System.out.println("Fine Details");

int fine=25+(extraTime-1)*10;

System.out.println("Fine is $"+fine);

}

}

//Class PoliceOfficer

public class PoliceOfficer

{

public static void main(String args[]) throws Exception

{

Scanner in=new Scanner(System.in);

String name;

int badge;

System.out.println("Enter Police Officer name");

name=in.nextLine();

System.out.println("Enter badge number");

badge=in.nextInt();

in.nextLine();

ParkedCar pc=new ParkedCar();

System.out.println("Enter Make");

pc.setMake(in.nextLine());

System.out.println("Enter Model");

pc.setModel(in.nextLine());

System.out.println("Enter Color");

pc.setColor(in.nextLine());

System.out.println("Enter Licence Number");

pc.setLicence(in.nextInt());

System.out.println("Enter Parking Time");

pc.setMinutes(in.nextInt());

System.out.println("Enter Number of Minutes Purchased");

int time=in.nextInt();

ParkingMeter pm=new ParkingMeter(time);

if(time<pc.getMinutes())

{

ParkingTicket pt=new ParkingTicket();

System.out.println("Police Officer "+name);

System.out.println("Badge Number "+badge);

pt.generateTicket(pc,time);

}

}

}