Question

In: Computer Science

Design a set of classes that work together to simulate a police officer issuing a parking...

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 classes' responsibilities are as the following:

-to know the make, the model, 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 simulated a parking ticket. The class's responsibilities are as follows:

-to report the make, model, and the license number of the illegally parked car

-to report the amount of the fine, which is $175 for the first hour and the part of an hour that the car illegally parked, plus $25 for every additional hour or part of the hour.

-to report the name and the badge number of the police officer issuing the ticket.

The policeOfficer Class: the class should simulate the officer inspecting parked cars. the class's responsibilities as follow:

-to know the police officers' name and badge number

-to examine a parkedCar object and parkingMeter object and determine whether the car's time has expired.

-to issue a parking ticket ( generate a parking ticket object) if the car's time has expired

Write a java program that demonstrate how these classes collaborate.

Solutions

Expert Solution

class ParkedCar
{
    public String make;
    public String model;
    public String license_number;
    public int num_of_minutes_parking;

    ParkedCar(String make, String model, String license_number, int time){
        this.make = make;
        this.model = model;
        this.license_number = license_number;
        this.num_of_minutes_parking = time;
    }

    public void setTime(int time){
        this.num_of_minutes_parking = time;
    }

}

class ParkingMeter
{
    public int parking_time_bought;

    ParkingMeter(int time){
        this.parking_time_bought = time;
    }
}

class ParkingTicket
{
    public ParkedCar car_instance;
    public ParkingMeter ticket_instance;
    public String police_name;
    public String badge_number;

    ParkingTicket(ParkedCar car_instance, ParkingMeter ticket_instance, String police_name, String badge_number)
    {
        this.car_instance = car_instance;
        this.ticket_instance = ticket_instance;
        this.police_name = police_name;
        this.badge_number = badge_number;
    }

    public void reportFine()
    {
        float fine = 0;
        float extra_time = car_instance.num_of_minutes_parking - ticket_instance.parking_time_bought;
        //System.out.println(extra_time);
        if(extra_time <= 60)    fine = 175*((float)extra_time/60);
        else    fine = 175 + 25*(float)(extra_time - 60)/60;
        System.out.println("Fine: Rs. "+( (float)Math.round(fine*100) / 100));
    }

    public void reportCar()
    {
        System.out.println("Car Details\nMake: "+car_instance.make+"\nModel: "+car_instance.model+"\nLicense Number: "+car_instance.license_number);
    }

    public void reportPoliceOfficer()
    {
        System.out.println("Police Officer Details\nName: "+police_name+"\nBadge Number: "+badge_number);
    }
}


class PoliceOfficer
{
    public String name;
    public String badge_number;
    private ParkingTicket newTicket;

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

    public boolean examine(ParkedCar car_instance, ParkingMeter ticket_instance)
    {
        if(ticket_instance.parking_time_bought < car_instance.num_of_minutes_parking)   return true;
        return false;
    }

    public void issueTicket(ParkedCar car_instance, ParkingMeter ticket_instance)
    {
        this.newTicket = new ParkingTicket(car_instance, ticket_instance, this.name, this.badge_number);
        System.out.println("Parking Ticket Issued: ");
        this.newTicket.reportFine();
        this.newTicket.reportCar();
        this.newTicket.reportPoliceOfficer();
    }
}

public class SampleTest
{
    public static void main(String [] args)
    {
        ParkedCar car_instance = new ParkedCar("Tesla", "Model S", "17BAN0135", 75);
        ParkingMeter ticket_instance = new ParkingMeter(50);
        PoliceOfficer po = new PoliceOfficer("Sgt. Adams K", "S14");
        if(po.examine(car_instance, ticket_instance))   po.issueTicket(car_instance, ticket_instance);
    }
}

Related Solutions

For this assignment you will design a set of classes that work together to simulate a...
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...
Parking Ticket simulator For this assignment you will design a set of classes that work together...
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....
parking Ticket simulator For this assignment you will design a set of classes that work together...
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....
Discuss how tribal police and local police agencies can work together to solve these crimes, to...
Discuss how tribal police and local police agencies can work together to solve these crimes, to educate the communities on these crimes, and what can be done collaboratively for better prevention of these type of crimes.
20 police officers work at Kadıköy Police Station. Each officer works for 5 days per week....
20 police officers work at Kadıköy Police Station. Each officer works for 5 days per week. The crime rate fluctuates with the day of week, so the number of the police officers required each day depends on which day of the week it is: Monday, 10; Tuesday, 13; Wednesday, 14; Thursday, 16; Friday, 14; Saturday, 18; Sunday, 10. The Police Station wants to schedule police officers to maximize the number of the officers whose days off are consecutive. Formulate an...
2 – The CPU design team is designing an instruction set with three classes of instructions....
2 – The CPU design team is designing an instruction set with three classes of instructions. Parameters are given in the following table. Consider a program with 65% ALU instructions, 20% memory access instructions, and 15% control instructions. What is the average CPI for this CPU? Clock Rate: 4GHz CPI for ALU Inst.: 4 CPI for Memory Inst.: 8 CPI for Control Inst.: 2
Discuss the four approaches (Per Capita, Minimum Staffing, Authorized Level, & Work-load Based) to police officer...
Discuss the four approaches (Per Capita, Minimum Staffing, Authorized Level, & Work-load Based) to police officer staffing and allocation
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT