Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is Java Docament2 Word ali alogaili Insert Draw Design Layout Referencrs Ma

ID: 3919420 • Letter: T

Question

This is Java

Docament2 Word ali alogaili Insert Draw Design Layout Referencrs Mailings Review View Tell me what you want to do Share File Home Cut Find 1 Copy Faste - Fomat Painter B IU NomalNo Spac Heading1 Heading Title Subtitla Subtlc Em Emphasis Intense EStronF Select Cinhoan Paragrap Styles 8. 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 Parkingteter 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 Policeotficer 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. Page 1 of 1 Uwords L Enaish Unted state:) + 100%

Explanation / Answer

/**
* The java program that collaborates all the classes
* to check a parked car is in excess of parking meter
* alloted time .If so, then the police office issue
* an ticket otherwise no ticket */
//ParkingCarDemo.java
public class ParkingCarDemo
{
   public static void main(String[] args)
   {

       //Create an instance of the ParkedCar with make,model,
       //color ,license and number of minutes parked
       ParkedCar car = new ParkedCar("Ford", "2018", "White", "AP0212", 100);
      
       //Create an instance of the parkingMeter that sets number of minutes to park
       ParkingMeter meter = new ParkingMeter(50);
       //Create an instance of the PoliceOffice with name and badge number
       PoliceOfficer officerMiller = new PoliceOfficer("Mark Twan", "0007");
      
       //Now call the patrol method that takes car and meter as input arguments and
       //returns ParkingTicket instance
       ParkingTicket ticket = officerMiller.patrol(car, meter);

       //Check if ticket object is not null then print the ticket
       if (ticket != null)
           System.out.println(ticket.toString());
       else
           //Otherwise print the No ticket issued message
           System.out.println("No ticket issued!");
      
   }
}//end of the Class

----------------------------------------------------------------------------------


//PoliceOfficer.java
public class PoliceOfficer
{
   private String name;
   private String badgeNo;

   public PoliceOfficer(String name, String badgeNo)
   {
       this.name = name;
       this.badgeNo = badgeNo;
   }
   public ParkingTicket patrol(ParkedCar car, ParkingMeter meter)
   {
       ParkingTicket ticket = new ParkingTicket(car, this, meter.getMinutesPurchased());
       ticket.setFine(ticket.calculateFine());
       if(ticket.getFine()==0.00)
       {
           return null;
       }
       return ticket;
   }

   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public String getBadgeNo() {
       return badgeNo;
   }
   public void setBadgeNo(String badgeNo) {
       this.badgeNo = badgeNo;
   }
   public String toString() {
       StringBuilder builder = new StringBuilder();
       builder.append(" Name:");
       builder.append(name);
       builder.append(" Badge Number:");
       builder.append(badgeNo);
       return builder.toString();
   }

}

----------------------------------------------------------------------------------

/*
* The java ParkingTicket that sets the car ,officer, and number of
* minutes parked in a constructor . The class has a method called
* calculateFine that calculates the fine for the car for the excess
* minutes parked.
* */
//ParkingTicket.java
public class ParkingTicket
{

   private ParkedCar car;
   private PoliceOfficer officer;
   private double fine;
   private int minutes;
   //Constant values for base fine and houly fine
   public static final double BASE_FINE=25.00;
   public static final double HOURLY_FINE=10.00;

   public ParkingTicket(ParkedCar car, PoliceOfficer officer, int minutes)
   {
       this.car = car;
       this.officer = officer;
       this.minutes = minutes;
   }

   public double calculateFine()
   {
       double hourlyFine = (minutes*HOURLY_FINE)/60;
       return BASE_FINE+hourlyFine;
   }
   public ParkedCar getCar()
   {
       return car;
   }
   public void setCar(ParkedCar car) {
       this.car = car;
   }
   public PoliceOfficer getOfficer()
   {
       return officer;
   }
   public void setOfficer(PoliceOfficer officer)
   {
       this.officer = officer;
   }
   public double getFine()
   {
       return fine;
   }
   public void setFine(double fine)
   {
       this.fine = fine;
   }
   public int getMinutes()
   {
       return minutes;
   }
   public void setMinutes(int minutes)
   {
       this.minutes = minutes;
   }
   public String toString()
   {
       StringBuilder builder = new StringBuilder();
       builder.append(" Car Details:");
       builder.append(car);
       builder.append(" Overtime Parked:");
       builder.append(minutes);
       builder.append(" Police Officer Details:");
       builder.append(officer);
       builder.append(" ================");
       builder.append(" Fine:");
       builder.append(String.format("%.2f", fine));
       builder.append(" ================");
      
       return builder.toString();
   }
}

----------------------------------------------------------------------------------

/**
* The class ParkingMeter that sets the number of
* minutes allowed to park the vehicle
* */
//ParkingMeter.java
public class ParkingMeter
{
   private int minutesPurchased;
   public ParkingMeter(int minutesPurchased)
   {
       this.minutesPurchased = minutesPurchased;
   }
   public int getMinutesPurchased()
   {
       return minutesPurchased;
   }
   public void setMinutesPurchased(int minutesPurchased)
   {
       this.minutesPurchased = minutesPurchased;
   }
}

----------------------------------------------------------------------------------


/*
* The java class ParkedCar that sets the make, model
* color, licence number and minuts parked
* */
//ParkedCar.java
public class ParkedCar
{

   private String make;
   private String model;
   private String color;
   private String liscenceNo;
   private int minutesParked;
   //Constructor to set the values of the private data members
   public ParkedCar(String make, String model, String color,
           String liscenceNo, int minutesParked)
   {
       this.make = make;
       this.model = model;
       this.color = color;
       this.liscenceNo = liscenceNo;
       this.minutesParked = minutesParked;
   }

   public String getMake() {
       return make;
   }
   public void setMake(String make) {
       this.make = make;
   }
   public String getModel() {
       return model;
   }
   public void setModel(String model) {
       this.model = model;
   }
   public String getColor() {
       return color;
   }
   public void setColor(String color) {
       this.color = color;
   }
   public String getLiscenceNo() {
       return liscenceNo;
   }
   public void setLiscenceNo(String liscenceNo) {
       this.liscenceNo = liscenceNo;
   }
   public int getMinutesParked() {
       return minutesParked;
   }
   public void setMinutesParked(int minutesParked) {
       this.minutesParked = minutesParked;
   }
   public String toString() {
       StringBuilder builder = new StringBuilder();
       builder.append(" Car:");
       builder.append(make);
       builder.append(" Model:");
       builder.append(model);
       builder.append(" Color:");
       builder.append(color);
       builder.append(" Plate:");
       builder.append(liscenceNo);
       builder.append(" minutesParked:");
       builder.append(minutesParked);
       return builder.toString();
   }

}

----------------------------------------------------------------------------------

Sample Output:


Car Details:
Car:Ford
Model:2018
Color:White
Plate:AP0212
minutesParked:100
Overtime Parked:50
Police Officer Details:
Name:Mark Twan
Badge Number:0007
================
Fine:33.33
================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote