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.

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

Mimir Requirements

File name to submit in mimir 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

ACTIONS

This is what I have so far

ParkedCar.java file------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class ParkedCar {

private String make = new String();

private String model = new String();

private String color = new String();

private String licenseNum = new String();

private int parkedMin;

public ParkedCar(String m1, String m2, String c, String l, int p)

{

make = m1;

model = m2;

color = c;

licenseNum = l;

parkedMin = p;

}

//Create Accessor methods to return Car info

public String getMake() {

return make;

}

public String getModel() {

return model;

}

public String getColor() {

return color;

}

public String getLicense() {

return licenseNum;

}

public int getParkedMinutes() {

return parkedMin;

}

//Create Mutator methods

public void setMake(String m1) {

make = m1;

}

public void setModel(String m2) {

model = m2;

}

public void setColor(String c) {

color = c;

}

public void setLicense(String l) {

licenseNum = l;

}

public void setParkedMinutes(int p) {

parkedMin = p;

}

}

ParkingTicket.java File------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class ParkingTicket {

private ParkedCar Car;

private PoliceOfficer officer;

private double fineAmount;

private int minutes;

//Constant

public final double firstHourFine = 25.0;

public final int additionalHourFine = 10;

//Constructor

public ParkingTicket(ParkedCar Car, PoliceOfficer officer) {

}

}

ParkingMeter.java file------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class ParkingMeter {

private int purchasedMin;

public ParkingMeter(int p)

{

purchasedMin = p;

}

//Create Accessor methods

public int getPurchasedMin() {

return purchasedMin;

}

//Create Mutator Methods

public void setPurchasedMin(int p) {

purchasedMin = p;

}

}

PoliceOfficer.java File ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class PoliceOfficer {

private String officerName;

private int badgeNum;

public PoliceOfficer(String name, int num) {

officerName = name;

badgeNum = num;

}

public String getName() {

return officerName;

}

public int getBadge() {

return badgeNum;

}

public void setName(String name) {

officerName = name;

}

public void setBadge(int num) {

badgeNum = num;

}

}

ParkingSimulatorTest.java file------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.Scanner;

public class ParkingSimulatorTest {

public static void main(String[] args) {

String officerName, carMake, carModel, carColor, carLicenseNum;

int minPurchased = 0, parkedMin, badgeNum;

//Create a Scanner object to accept user input

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the officer's name");

officerName = keyboard.nextLine();

System.out.println("Enter officer's badge number");

badgeNum = keyboard.nextInt();

System.out.println("Enter the car's make");

carMake = keyboard.next();

System.out.println("Enter the car's model");

carModel = keyboard.nextLine();

System.out.println("Enter the car's color");

carColor = keyboard.nextLine();

System.out.println("Enter the car's liscense number");

carLicenseNum = keyboard.nextLine();

System.out.println("Enter Minutes on car");

parkedMin = keyboard.nextInt();

System.out.println("Enter the number of minutes purchased on the meter");

//Create Police Officer Object

PoliceOfficer policeOfficer = new PoliceOfficer(officerName, badgeNum);

//Create car Object

ParkedCar parkedCar = new ParkedCar(carMake, carModel, carColor, carLicenseNum, parkedMin);

//Create a parking meter object

ParkingMeter meter = new ParkingMeter(minPurchased);

}

Please Help I need to know If I am on the right track and what other things do I need.

Solutions

Expert Solution

import java.io.*;

import java.util.Scanner;

/* ParkedCar class */

class ParkedCar

{

/* variable declarations */

     private String carMake;

    private String carModel;

    private String carColor;

    private String carLicenseNo;

    private int minsParked;

     /* Constructor */

    public ParkedCar(String cmak, String cmod, String ccol, String cLno,

     int mins)

     {

          this.carMake = cmak;

        this.carModel = cmod;

this.carColor = ccol;

        this.carLicenseNo = cLno;

          this.minsParked = mins;

    }

     /* Constructor */

    public ParkedCar(ParkedCar car1)

     {

          this.carMake = car1.carMake;

        this.carModel = car1.carModel;

        this.carColor = car1.carColor;

        this.carLicenseNo = car1.carLicenseNo;

        this.minsParked = car1.minsParked;

    }

     /* set method for Make */

    public void setCarMake(String m)

     {

          this.carMake = m;

    }

     /* set method for Model */

    public void setCarModel(String m)

     {

          this.carModel = m;

    }

     /* set method for Color */

    public void setCarColor(String c)

     {

          this.carColor = c;

    }

     /* set method for LicenseNo */

    public void setCarLicenseNo(String cLno)

     {

          this.carLicenseNo = cLno;

    }

     /* set method for MinutesParked */

    public void setMinsParked(int m)

     {

          this.minsParked = m;

    }

     /* get method for Make */

    public String getCarMake()

     {

          return carMake;

    }

     /* get method for Model */

    public String getCarModel()

     {

          return carModel;

    }

     /* get method for Color */

    public String getCarColor()

     {

          return carColor;

    }

     /* get method for LicenseNo */

    public String getCarLicenseNo()

     {

          return carLicenseNo;

    }

     /* get method for MinutesParked */

    public int getMinsParked()

     {

          return minsParked;

    }

     /* method to print details */

    public String toString()

     {

String newString = "CarMake: " + carMake + "\nCarModel: " + carModel + "\nCarColor: " + carColor + "\nLicenseNo: " + carLicenseNo + "\nMinutesParked: " + minsParked;

        return newString;

    }

}

/* ParkingMeter Class */

class ParkingMeter

{

/* variable declarations */

     int minsForParking;

     /* get method for minutes for parking */

    public int getMinsForParking()

     {

          return minsForParking;

    }

     /* set method for minutes for parking */

    public void setMinsForParking(int minsForParking)

     {

          this.minsForParking = minsForParking;

    }

}

/* ParkingTicket Class */

class ParkingTicket

{

/* variable declarations */

     int fineAmount;

    int illegalParkedHour;

    /* get method for FineAmount */

     public int getFineAmount()

     {

          return fineAmount;

    }

     /* set method for FineAmount */

    public void setFineAmount(int fineAmount)

     {

          this.fineAmount = fineAmount;

    }

     /* method for generating report */

void reportIllegalParkedCar(ParkedCar myPC, ParkingMeter myPM, PoliceOfficer myPO)

     {

          System.out.println("Illegally parked car details :");

        System.out.println("carMake :" + myPC.getCarMake());

        System.out.println("carModel :" + myPC.getCarModel());

        System.out.println("carColor :" + myPC.getCarColor());

          System.out.println("carLicenceNo :" + myPC.getCarLicenseNo());

        illegalParkedHour =

((myPC.getMinsParked() - myPM.getMinsForParking()) / 60) + 1;

        if (illegalParkedHour <= 1)

              setFineAmount(25);

        else

              setFineAmount(25 + ((illegalParkedHour - 1) * 10));

        System.out.println("FineAmount : $" + getFineAmount());

        System.out.println("Name of Police officier :"

+ myPO.getPoliceName());

        System.out.println("BadgeNumber :" + myPO.getBadgeNo());

    }

}

/* PoliceOfficer class */

public class PoliceOfficer

{

/* variable declarations */

     String policeName;

    int badgeNo;

     /* get method for PoliceName */

    public String getPoliceName()

     {

          return policeName;

   }

     /* set method for PoliceName */

    public void setPoliceName(String policeName)

     {

          this.policeName = policeName;

    }

     /* get method for BadgeNo */

    public int getBadgeNo()

     {

          return badgeNo;

    }

     /* set method for BadgeNo */

    public void setBadgeNo(int badgeNo)

     {

          this.badgeNo = badgeNo;

    }

     /* method to check time */

    boolean expired(int timePurchace, int timeParked)

     {

          if (timeParked - timePurchace > 0)

              return true;

        else

              return false;

    }

     /* object creation for ParkedCar class */

    ParkedCar myPC = new ParkedCar(null, null, null, null, 0);

    /* object creation for ParkingMeter class */

     ParkingMeter myPM = new ParkingMeter();

     /* main method */

    public static void main(String[] args)

     {

          /* boolean declaration */

          boolean state;

          /* object creation for PoliceOfficer class */

        PoliceOfficer myPO = new PoliceOfficer();

        System.out.println("Enter police officer name :");

          Scanner newSc = new Scanner(System.in);

        myPO.setPoliceName(newSc.nextLine());

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

        myPO.setBadgeNo(newSc.nextInt());

        System.out.println("Enter carMake:");

        myPO.myPC.setCarMake(newSc.next());

        System.out.println("Enter carModel:");

        myPO.myPC.setCarModel(newSc.next());

        System.out.println("Enter carColor:");

        myPO.myPC.setCarColor(newSc.next());

        System.out.println("Enter carLicenceNo:");

        myPO.myPC.setCarLicenseNo(newSc.next());

        System.out.println("Enter minutes car parked:");

        myPO.myPC.setMinsParked(newSc.nextInt());

        System.out.println("Enter minutes purchased for parking:");

        myPO.myPM.setMinsForParking(newSc.nextInt());

        state = myPO.expired(myPO.myPM.getMinsForParking(),

myPO.myPC.getMinsParked());

        if (state == true)

          {

               /* object creation for ParkingTicket class */

              ParkingTicket pt = new ParkingTicket();

            pt.reportIllegalParkedCar(myPO.myPC, myPO.myPM, myPO);

        }

          else

              System.out.println("Car is parked Legally!");

    }

}


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...
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...
In this assignment, design an ANOVA test . Identify the factors and levels in you design....
In this assignment, design an ANOVA test . Identify the factors and levels in you design. Is it a one factor study or multi factor between-subjects design?
For this assignment, you will create a hierarchy of five classes to describe various elements of...
For this assignment, you will create a hierarchy of five classes to describe various elements of a school setting. The classes you will write are: Person, Student,Teacher, HighSchoolStudent, and School. Detailed below are the requirements for the variables and methods of each class. You may need to add a few additional variables and/or methods; figuring out what is needed is part of your task with this assignment. Person Variables: String firstName - Holds the person's first name String lastName -...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT