Question

In: Computer Science

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. 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

Solutions

Expert Solution

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);
    }
}

Related Solutions

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....
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...
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...
Java ArrayList Parking Ticket Simulator, Hello I am stuck on this problem where I am asked...
Java ArrayList Parking Ticket Simulator, Hello I am stuck on this problem where I am asked to calculate the sum of all fines in the policeOfficer class from the arraylist i created. I modified the issueParking ticket method which i bolded at the very end to add each issued Parking ticket to the arrayList, i think thats the right way? if not please let me know. What I dont understand how to do is access the fineAmountInCAD from the arrayList...
When you take the effort to dispute a parking ticket, you must take into account the...
When you take the effort to dispute a parking ticket, you must take into account the cost of your time, which is called: explicit cost accounting cost economic cost opportunity cost When making decisions, welfare is maximized when: marginal cost equals opportunity cost marginal cost equals marginal benefit marginal cost equals total benefit marginal cost equals total cost If you paid $18 for an “unlimited play” pass at Boomers Fun Center, what is the marginal cost of the 3rd round...
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
1. In this assignment, you will use MARS(MIPS Assembler and Runtime Simulator) to write and run...
1. In this assignment, you will use MARS(MIPS Assembler and Runtime Simulator) to write and run a program that reads in a string of ASCII characters and converts them to Integer numbers stored in an array. There are two different ways to convert the number into ASCII, subtraction and “masking”. If your student ID ends in an odd number, then use subtraction. If your student ID ends in an even number, then use masking. Write a program that: 1.Inputs a...
Assignment 1: JAVA Classes, Objects, and Constructors The goal of this assignment is to get you...
Assignment 1: JAVA Classes, Objects, and Constructors The goal of this assignment is to get you familiar with some of the most used JAVA syntax, as well as constructors objects, objects calling other objects, class and instance attributes and methods. You will create a small program consisting of Musician and Song classes, then you will have Musicians perform the Songs. Included is a file “Assignment1Tester.java”. Once you have done the assignment and followed all instructions, you should be able to...
C++ Assignment 1: Make two classes practice For each of the two classes you will create...
C++ Assignment 1: Make two classes practice For each of the two classes you will create for this assignment, create an *.h and *.cpp file that contains the class definition and the member functions. You will also have a main file 'main.cpp' that obviously contains the main() function, and will instantiate the objects and test them. Class #1 Ideas for class one are WebSite, Shoes, Beer, Book, Song, Movie, TVShow, Computer, Bike, VideoGame, Car, etc Take your chosen class from...
Assignment Details For this assignment, suppose that you work for a consulting firm, and that you...
Assignment Details For this assignment, suppose that you work for a consulting firm, and that you have been asked to research a company and make a presentation to your client.   For the presentation: Choose a major U.S. company, Research the company and the market(s) in which it competes, and Prepare a presentation of 10-12 PowerPoint slides (with detailed speaker notes). Using information from the business press, AIU's Library, IBIS World, and the Internet, address the following in your slides: Describe...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT