I have attached 4 classes which I have created for the following assignment, as well as a test program which tests the other four classes. The only thing that I am having a problem with is reporting the amount of the fine in the ParkingTicket class, as well as determining if the time has expired in the PoliceOfficer class (and generating a ticket). I have obtained these through output in the MeterTest class. However the assignment calls for these operations to be done in their respective classes. I am not sure how do so... If you can help I would appreciate it...

Design a set of classes that work together to simlulate 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.

You were told to use get, set methods in your class and you used only a set method that changes all the variables of your class. In class: policeOfficer for example you have only a set method which is not what was suggested. Plus the attributes are declared private meaning no one is going to be able to read them.
Rewrite your classes using this example, and rename them so the first letter would be a capital one:

import java.util.Scanner;

public class PoliceOfficer 
{
    private String officerName;
    private int badgeNumber;
    
    public PoliceOfficer (String on, int bn)
    {
        officerName = on;
        badgeNumber = bn;
    }

    public PoliceOfficer (PoliceOfficer cp) 
    {
         officerName = cp.getOfficerName();
         badgeNumber = cp.getBadgeNumber();
    }

    public void setOfficerName (String on)
    {
        officerName = on;
    }

    public void setBadgeNumber(int bn)
    {
        badgeNumber = bn;
    }

    public String getOfficerName ()
    {
        return officerName;
    }

    public int getBadgeNumber()
    {
        return badgeNumber;
    }
    
    public String toString()
    {
        String str = "Officer Name: " + officerName
                + "\nBadge Number: " + badgeNumber;
    
    
    return str;
    }
}

Pay attention to which letters I chose to capitalize at the methods:

getBadgeNumber
getOfficerName

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.

That means that the PoliceOfficer class should have 2 more attributes:
parked car object and ParkingMeter object :
ParkedCar,
ParkingMeter

In your main you did these calculations:

difference = utimeParked - utimePurchased;
        if (difference < 0)

The utimeParked is part of the ParkedCar that the PoliceOfficer will have
The utimePurchased is part of the ParkingMeter that the PoliceOfficer will have

So write a method in the PoliceOfficer class that uses the above values taken from the objects ParkedCar, ParkingMeter that PoliceOfficer has.

PoliceOfficer {
  ParkedCar car;
  ParkingMeter meter;
  
  ....
  ....

  public ParkingTicket issueTicket() {
   //in here you will do the calculations
  //and return a ParkingTicket object
     difference = car.getMinutesParked() - meter.getMinutesPurchased();
   // do the calculations
  instantiate a ParkingTicket object and return it.
  }
}

I order for the issueTicket() method to work, the ParkingTicket will have to have these attributes:
ParkedCar,
PoliceOfficer,
AND:
amount of money to be paid.

You will not create ParkingTicket in main. You will get it when you call the issueTicket() and print what is recquired

commented: Helpful explanations in this thread. +12

Just 2 tips about the issueTicket method:

1) You should change this:

if (difference < 0)
 .....
else if (difference > 0 && difference < 60)
.....
else if (difference > 60 && difference < 120)

To this:

if (difference <= 0)
 .....
else if (difference > 0 && difference <= 60)
.....
else if (difference > 60 && difference <= 120)

Because if the diif is exactly 60 or 120 then you will print nothing.

Also when you are in the PoliceOfficer class and you would want to create a ParkingTicket object that has a PoliceOfficer variable then you can do this: new ParkingTicket(car, this);

can somebody help me with code of this question?

Design and implement a class 'ParkingMeter' for parking meters. A user can insert quarters and check remaining parting time. The constructor should take the maximum parking minutes and the rate (minutes per quarter).

If the existing code in this thread doesn't cover you, start your own thread.
Also it is best to show what you have done so far if you want to get any help

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.