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.

Attachments
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Cory
 */
public class MeterTest 

{
    
    public static void main(String[] args)
    {
        String umake;
        String umodel;
        String ucolor;
        String uname;
        int ulicenseNumber;
        int utimeParked;
        int utimePurchased;
        int ubadgeNumber;
        int difference;
        int fineAmount;
        
        
        
        Scanner keyboard = new Scanner(System.in);
        
        System.out.println("Enter Officer: ");
        uname = keyboard.nextLine();
        
        System.out.println("Enter Make: ");
        umake = keyboard.nextLine();
        
        System.out.println("Enter Model: ");
        umodel = keyboard.nextLine();
        
        System.out.println("Enter Color: ");
        ucolor = keyboard.nextLine();
        
        System.out.println("Enter License Number: ");
        ulicenseNumber = keyboard.nextInt();
        
        System.out.println("Enter Time Parked: ");
        utimeParked = keyboard.nextInt();
        
        System.out.println("Enter Time Purchased: ");
        utimePurchased = keyboard.nextInt();
        
        System.out.println("Enter Badge Number: ");
        ubadgeNumber = keyboard.nextInt();
        
        
        
        
        
        parkedCar carTest = 
                new parkedCar(umake, umodel, ucolor, ulicenseNumber, utimeParked);
        
        parkingMeter meterTest = 
                new parkingMeter (utimePurchased);
        
        policeOfficer  officerTest= 
                new policeOfficer (uname, ubadgeNumber);
        
        parkingTicket ticketTest = 
                new parkingTicket(carTest, officerTest);
        
      
        difference = utimeParked - utimePurchased;
        if (difference < 0)
            System.out.println("No ticket!");
        else if (difference > 0 && difference < 60)
            System.out.println(" Fine: $25");
        else if(difference > 60 && difference < 120)
            System.out.println("Fine: $35");
        else if(difference > 120 && difference < 180)
            System.out.println("Fine: $45");
        else if(difference > 180 && difference < 240)
            System.out.println("Fine: $55");
        else if(difference > 240 && difference < 300)
            System.out.println("Fine: $65");
        else if(difference > 300 && difference < 360)
            System.out.println("Fine: $75");
        else if(difference > 360 && difference < 420)
            System.out.println("Fine: $85");
        else if(difference > 420 && difference < 480)
            System.out.println("Fine: $95");
        
            
        
        
          System.out.println(ticketTest);
    }
    

}
import java.util.Scanner;


public class parkedCar 

{
       
    private String make;
    private String model;
    private String color;
    private int licenseNumber;
    private int minutesParked;
    
   public parkedCar(String mk, String mod, String col, int ln, int mp)
   {
       make = mk;
       model = mod;
       color = col;
       licenseNumber = ln;
       minutesParked = mp;
   }

    parkedCar(parkedCar c) 
    {
        make = c.make;
        model = c.model;
        color = c.color;
        licenseNumber = c.licenseNumber;
        minutesParked = c.minutesParked;
    }
    
   
   public void set(String mk, String mod, String col, int ln, int mp)
   {
       make = mk;
       model = mod;
       color = col;
       licenseNumber = ln;
       minutesParked = mp;
   }
   
   public String getMake()
   {
       return make;
   }
   public String getModel()
   {
       return model;
   }
   
   public String getColor()
   {
       return color;
   }
   public int getlicenseNumber()
   {
       return licenseNumber;
   }
   public int getMinutesParked()
   {
       return minutesParked;
   }
   
   
   
   public String toString()
   {
       String str = "Make: " + make
               + "\nModel: " + model
               + "\nColor: " + color
               + "\nLicense Number: " + licenseNumber
               + "\nMinutes Parked: " + minutesParked;
       
       return str;
               
               
   }
    
    

}
import java.util.Scanner;


public class parkingMeter 
{
    private int minutesPurchased;
        
        
    public parkingMeter(int mp)
    {
        minutesPurchased = mp;
    }
     
    public void set(int mp)
    {
        minutesPurchased = mp;
 
    }
    
    public double getMinutesPurchased()
    {
        return minutesPurchased;
    }
    
    
    public String toString()
    {
        String str = "Minutes purchased: " + minutesPurchased;
        
        return str;
    }
}
class parkingTicket 
 {
    
    private parkedCar car;
    private policeOfficer cop;
    
    
    public parkingTicket(parkedCar c, policeOfficer cp)
    {
       
        car = new parkedCar(c);
        cop = new policeOfficer(cp);   
    }
    
    
    public parkedCar getParkedCar()
    {
        return new parkedCar(car);
    }
    
    public policeOfficer getpoliceOfficer()
    {
        return new policeOfficer(cop);
    }
    
    public String toString()
    {
        String str = "Car Information: \n" + car
                + "\nOfficer Information: \n" + cop;
        
        return str;
        
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
 }
import java.util.Scanner;

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

    policeOfficer(policeOfficer cp) 
    {
         officerName = cp.officerName;
         badgeNumber = cp.badgeNumber;
    }

    public void set(String on, int bn)
    {
        officerName = on;
        badgeNumber = bn;
    }
    
    public String toString()
    {
        String str = "Officer Name: " + officerName
                + "\nBadge Number: " + badgeNumber;
    
    
    return str;
    }
}

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

Comments
Helpful explanations in this thread.

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

This article has been dead for over six months. Start a new discussion instead.