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

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....
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
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...
C++ In this assignment you will use your Card class to simulate a deck of cards....
C++ In this assignment you will use your Card class to simulate a deck of cards. You will create a Deck class as follows: The constructor will create a full 52-card deck of cards. 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace for each suit: Clubs, Diamonds, Hearts, Spades Each card will be created on the heap and the deck will be stored using an STL vector of Card pointers. The destructor will free the...
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...
Question 1. In this exercise you will simulate a data set and run a simple regression....
Question 1. In this exercise you will simulate a data set and run a simple regression. To ensure reproducible results, make sure you use set.seed(1). a)   Using the rnorm() function create vector X that contains 200 observations from N(0,1) distribution. Similarly, create a 200 element vector, epsilon (ϵ), drawn from N(0,0.25) distribution. This is the irreducible error. b)   Create the response data using the following relationship: Y=−1+0.5X+ϵ Fit a linear regression of Y on X. Display the summary statistics and...
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?
Problem 1: Simulating Blackjack In this problem we will use classes and functions to simulate a...
Problem 1: Simulating Blackjack In this problem we will use classes and functions to simulate a simplified game of Blackjack (21). The game begins with a standard deck of 52 playing cards (no jokers). Each player is dealt two cards to start with. The winner of a hand of Blackjack is the player whose hand has the highest value without going over 21. When calculating the value of a hand, we add up the rank of each card in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT