Hello, I am doing the infamous Parking Ticket Simulator for my Java class at college. I have already completed the program and it producing the correct output. The only issue however, is that I am NOT using the PoliceOfficer class to issue the ticket. In other words, he is not checking to see if a ticket should be issued. Instead I have managed to make the ParkingTicket class do it. But the instructions require me to have the PoliceOfficer issue the ticket, NOT to have the ParkingTicket do it; which is how I got it to work. Im having trouble figuring out how to make the PoliceOfficer issue the ticket. Much appreciated as to who can help me with this. Here are the codes. The real issues are with the ParkingTicket class and the PoliceOfficer Class. The last code provided is the Demo. Also here are the instructions:

Design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes to design are:

  • ParkedCar class: simulates a parked car
  • This class knows the car's make, model, color, license number, and the number of minutes that the car has been parked.

  • ParkingMeter Class: simulates a parking meter.

  • This classes only responsibility is to know the number of minutes of parking time that has been purchased.

-ParkingTicket class: Simulates a parking ticket
Responsibilities:
- To report make, model, color, and license number of the illegally parked car.
- To report the amount of the fine which is $25 dollars for the first hour or part of the hour that the car is illegally parked, plus $10 for every additional hour or part of an hour that the car is parked.
- To report the name and badge number of the police officer issuing the ticket.
-PoliceOfficer class: Simulates a police officer
Responsibilities:
- To know the police officer's name and badge number
- To examine a parked car 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 to test the classes as well.

public class ParkedCar
{
   private String make;
   private String model;
   private String color;
   private String licenseNumber;
   public int minutes;

   //Constructor with no arguments
   public ParkedCar()
   {
      make = "";
      model = "";
      color = "";
      licenseNumber = "";
      minutes = 0;
   }

   //constructor with arguments
   public ParkedCar(String cMake, String cModel,
                    String cColor, String cLicenseNum, int cMinutes)
   {
      make = cMake;
      model = cModel;
      color = cColor;
      licenseNumber = cLicenseNum;
      minutes = cMinutes;
   }

   //The set method sets a value for each field 
   public void set(String carMake, String carModel,
                   String carColor, String carLicenseNum,
                   int carMinutes)
   {
      make = carMake;
      model = carModel;
      color = carColor;
      licenseNumber = carLicenseNum;
      minutes = carMinutes;
   }

   //copy constructor initializes
   //the object as a copy of another
   //instructor object. 
   public ParkedCar(ParkedCar object2)
   {
      make = object2.make;
      model = object2.model;
      color = object2.color;
      licenseNumber = object2.licenseNumber;
      minutes = object2.minutes;
   }

   public String getMake()
   {
      return make;
   }

   public String getModel()
   {
      return model;
   }

   public String getColor()
   {
      return color;
   }

   public String getLicenseNumber()
   {
      return licenseNumber;
   }

   public int getMinutes()
   {
      return minutes; 
   }

   //converts everything into a string  
   public String toString()
   {
      String str = "\nMake: " + make +
                   "\nModel: " + model + 
                   "\nColor: " + color +
                   "\nLicense number: " + licenseNumber +
                   "\nMinutes parked: " + minutes;
      return str;
   }

   //comparing
   public boolean equals(ParkedCar ParkedCar2)
   {
      boolean status;

      if(make.equals(ParkedCar2.make) &&
         model.equals(ParkedCar2.model) &&
         color.equals(ParkedCar2.color) &&
         licenseNumber.equals(ParkedCar2.licenseNumber))

         status = true;
      else
         status = false;

      return status;      
   }
}





public class ParkingMeter
{
   public int minutesPurchased;

   //with no arguments 
   public ParkingMeter()
   {
      minutesPurchased = 0; 
   }

   //constructor with arguments
   public ParkingMeter(int purchase)
   {
      minutesPurchased = purchase;
   }

   //set method
   public void set(int purchase)
   {
      minutesPurchased = purchase;
   }

   //return method
   public int getMinutesPurchased()
   {
      return minutesPurchased; 
   }

   public ParkingMeter(ParkingMeter object2)
   {
      minutesPurchased = object2.minutesPurchased;  
   }

   public String toString()
   {
      String str = "\nMinutes purchased: " + minutesPurchased;

      return str;   
   }  

   public boolean equals(ParkingMeter ParkingMeter2)
   {
      boolean status;

      if(minutesPurchased == ParkingMeter2.minutesPurchased)
         status = true;
      else
         status = false;

      return status;      
   }
}







public class ParkingTicket
{
   private ParkedCar car;
   private PoliceOfficer officer;
   private ParkingMeter meter;
   double baseFine = 25.0;
   double hourlyFine = 10.0;




   public ParkingTicket()
   {  
      car = new ParkedCar();
     officer = new PoliceOfficer();
      meter = new ParkingMeter();
   } 

   public ParkingTicket(ParkedCar c, PoliceOfficer o,
                        ParkingMeter m)
   {
      car = new ParkedCar(c);
      officer = new PoliceOfficer(o);
      meter = new ParkingMeter(m);  
   }  

   public ParkingTicket(ParkingTicket object2)
   {
      car = object2.car;
      officer = object2.officer;
      meter = object2.meter;

   }                   

   public ParkedCar getParkedCar()
   {
      return new ParkedCar(car);
   }

   public PoliceOfficer getPoliceOfficer()
   {
      return new PoliceOfficer(officer);
   }

   public ParkingMeter getParkingMeter()
   {
      return new ParkingMeter(meter);
   }

   public double getFine()
   {
      double ticket;

      if (car.minutes <= meter.minutesPurchased)
      {
         ticket = 0;
      }
      else
         ticket = baseFine + (hourlyFine * ((car.minutes - meter.minutesPurchased) / 60)); 

      return ticket;    

   }

   public String toString()
   {
      String str = "\nVehicle information:\n" +
                  car +
                  "\n\nOfficer information:\n" +
                  officer + 
                  "\nFine: $" + getFine();
      return str;
   }

   public boolean equals(ParkingTicket ParkingTicket2)
   {
      boolean status;

      if(car.equals(ParkingTicket2.car) &&
         officer.equals(ParkingTicket2.officer) &&
         meter.equals(ParkingTicket2.meter) &&
         getFine() == ParkingTicket2.getFine())

         status = true;
      else
         status = false;

      return status;      
   }
}






public class PoliceOfficer
{
   private String name;
   private int badgeNumber;

   private ParkedCar car;
   private ParkingMeter meter;
   public ParkingTicket ticket;


   public PoliceOfficer()
   {
      name = "";
      badgeNumber = 0;
      car = new ParkedCar();
      meter = new ParkingMeter();
      ticket = new ParkingTicket();
   }

   public PoliceOfficer(String officerName, int officerBadge)

   {
      name = officerName;
      badgeNumber = officerBadge;
   }

   public void set(String officerName, int officerBadge)
   {
      name = officerName;
      badgeNumber = officerBadge;
   }

   public PoliceOfficer(PoliceOfficer object2)
   {
      name = object2.name;
      badgeNumber = object2.badgeNumber;
   }

   public String getOfficerName()
   {
      return name; 
   }

   public int getOfficerBadgeNumber()
   {
      return badgeNumber; 
   }


    public ParkedCar getParkedCar()
   {
      return new ParkedCar(car);
   }

   public ParkingMeter getParkingMeter()
   {
      return new ParkingMeter(meter);
   }

   public ParkingTicket getParkingTicket()
   {
      return new ParkingTicket(ticket);
   }

   public ParkingTicket ticket(ParkedCar car, ParkingMeter meter)
   {

      if(car.minutes > meter.minutesPurchased)
         return new ParkingTicket(ticket);
      else
         return null;
   }

   public String toString()
   {
      String str = "\nOfficer name: " + name +
                   "\nBadge number: " + badgeNumber;
      return str;
   }

   public boolean equals(PoliceOfficer PoliceOfficer2)
   {
      boolean status;

      if(name.equals(PoliceOfficer2.name) &&
         badgeNumber == PoliceOfficer2.badgeNumber &&
         ticket.equals(PoliceOfficer2.ticket))
         status = true;
      else
         status = false;

      return status;      
   }
}






public class ParkingTicketDemo
{
   public static void main(String[] args)
   {
      ParkedCar myCar = new ParkedCar("Ford", "Mustang","Red", "LMJCD",40);
      ParkingMeter myMeter = new ParkingMeter(60);
      PoliceOfficer myOfficer = new PoliceOfficer("Dane", 5565);
      ParkingTicket myTicket = new ParkingTicket(myCar,myOfficer, myMeter);

      System.out.println(myMeter);
      System.out.println(myTicket);
   }
}

This is a model of a real-life situation, so think about what happens in real life.
There are mulitple parked cars and meters. There is a policeman. The policeman looks at all the parked cars and meters, one at a time. If the parking is illegal the policeman creates a new parking ticket with the car and meter details on it. That's what the code in your PoliceMan class should do. Don't start with the instance variables, start with that code (method), and add instance variables as the code needs them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.