Question

In: Computer Science

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 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. Make the aforementioned classes nested classes within the class containing your main method; only this outermost class can be declared public.

Sample Run
java ParkingTicketSimulator

===·Parking·Ticket·Simulator·===↵

---------↵
Car·Data↵
---------↵

·Enter·car·make:Bugatti↵
·Enter·car·model:Veyron↵
·Enter·car·color:Black↵
·Enter·car·license·number:ESC-1532↵
·Enter·minutes·car·has·been·parked:450↵
·↵
----------↵
Meter·Data↵
----------↵
↵ Enter·minutes·purchased·by·driver:60↵
·↵
-------↵
PO·Data↵
-------↵

Enter·police·officer's·name:Robert·Smith↵
·Enter·police·officer's·badge·number:230475↵
·↵ ---------------------↵
Parking·Ticket·Issued↵
---------------------↵

|·Parking·ticket·#:·.·.·.↵
|·Fined·amount:·$75.00↵
|·Car·issued·to:·Black·Bugatti·Veyron,·license·#:·ESC-1532↵
|·Issued·by·officer:·Robert·Smith,·badge·#:·230475↵

Solutions

Expert Solution

[Note the fine output in the question doesn't match with the question as if we divide 450 by 60 we will get 7.5 hrs so for the first-hour car will be charged $25 and the rest 6.5 hrs car will be charged $70 as part of the hour is also considered so the all total fine will be $95]

if you have any question regarding the program feel free to comment

Program

package parkingTicketSimulation;

import java.util.Scanner;

public class ParkingTicketSimulation {
  
   //nested classes
   static class ParkedCar {
       private String make, model, color, license;
       private int noOfMin;

       public ParkedCar(String make, String model, String color, String license, int noOfMin) {
           this.make = make;
           this.model = model;
           this.color = color;
           this.license = license;
           this.noOfMin = noOfMin;
       }

       public int getNoOfMin() {
           return noOfMin;
       }

       @Override
       public String toString() {
           return color+" "+make+" "+model+", License #: "+license;
       }

   }
  
   static class ParkingMeter {
       private int purchasedParkTime;

       public ParkingMeter(int purchasedParkTime) {
           this.purchasedParkTime = purchasedParkTime;
       }

       public int getPurchasedParkTime() {
           return purchasedParkTime;
       }
   }
  
   static class PoliceOfficer {
       private String name;
       private int badgeNo;
      
       public PoliceOfficer(String name, int badgeNo) {
           this.name = name;
           this.badgeNo = badgeNo;
       }
      
       public void examin(ParkedCar car, ParkingMeter meter) {
           //when car min exceeds its purachse min officer will issue ticket
           if(car.getNoOfMin() > meter.getPurchasedParkTime()) {
               System.out.println("Parking ticket issued");
               ParkingTicket.report(car, meter, this);
           }
           else {
               System.out.println("No parking ticket issued for ");
               System.out.println(car);
           }
       }
      
       @Override
       public String toString() {
           return name+", badge#: "+badgeNo;
       }
      
   }
  
   static class ParkingTicket {
       private static int ticketNo=0;
      
       public static void report(ParkedCar car, ParkingMeter meter, PoliceOfficer officer) {
           ticketNo++;//will increment with every issue
           int fine = 0;
           int noOfHours = car.getNoOfMin() / meter.getPurchasedParkTime();
           int noOfRemainHours = car.getNoOfMin() % meter.getPurchasedParkTime();
          
           //part of first hour fine
           if(noOfRemainHours != 0 && noOfHours<1) {
               fine+=25;
           }
           else {
               if(noOfHours>=1) {//first hour fine plus additional hour
                   fine+=25 + ((noOfHours-1)*10);
               }
               if(noOfRemainHours != 0)//part of additional hour
                   fine+=10;
           }
          
           System.out.println("Parking ticket#: "+ticketNo);
           System.out.println("Fined amount: $"+fine);
           System.out.println("Car issued to: "+car);
           System.out.println("Issued by officer: "+officer);
          
       }
   }
  
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
      
       String make, model, color, license, name;
       int noOfMin, purchasedParkTime, badgeNo;
      
       System.out.println("Car Data");
       System.out.print("Enter car make: "); make = sc.nextLine();
       System.out.print("Enter car model: "); model = sc.nextLine();
       System.out.print("Enter car color: "); color = sc.nextLine();
       System.out.print("Enter car license number: "); license = sc.nextLine();
       System.out.print("Enter minutes car has been parked: "); noOfMin = sc.nextInt();
       sc.nextLine();
      
       System.out.println("\nMeter Data");
       System.out.print("Enter minutes purchased by driver: ");purchasedParkTime= sc.nextInt();
       sc.nextLine();
      
       System.out.println("\nPO Data");
       System.out.print("Enter police officer's name: "); name = sc.nextLine();
       System.out.print("Enter police officer's badge number: "); badgeNo = sc.nextInt();
       sc.nextLine();
      
       System.out.println();
       ParkingTicketSimulation.ParkedCar car = new ParkedCar(make, model, color, license, noOfMin);
       ParkingTicketSimulation.ParkingMeter meter = new ParkingMeter(purchasedParkTime);
       ParkingTicketSimulation.PoliceOfficer officer = new PoliceOfficer(name, badgeNo);
       officer.examin(car, meter);
       sc.close();
   }
}

Output


Related Solutions

Using C++. For this assignment you will design a set of classes that work together to...
Using C++. 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 responsibilities are: -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: -To know...
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...
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....
For this assignment you will create a set of simple classes that model a cookbook. The...
For this assignment you will create a set of simple classes that model a cookbook. The cookbook will consist of set or recipes. Each recipe will consist of a set of ingredients and instructions. Your submission will consist of the below three classes and a test driver (the only class with a main()) that exercises the functionality of your system. You will need to implement the following classes based on the description of their attributes and operations: Ingredient name -...
Design a set of classes that keeps track of demographic information about a set of people,...
Design a set of classes that keeps track of demographic information about a set of people, such as age, nationality, occupation, income, and so on. Design each class to focus on a particular aspect of data collection. Assume the input data is coming from a text file. Create a main driver class to instantiate several of the classes.
Developing a set of classes demonstrating inheritance - in class work
Developing a set of classes demonstrating inheritance - in class work
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
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...
Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode)...
Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack.   When the player attacks, it will pick a random number between 0 and up to the maximum damage the player does, and then subtract that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT