Having a real difficulty understanding how to implement aggregation. I am currently working on a project that is called parking ticket. One class represents the parked car and defines the description of it. Then theres parking meter class that holds how much time is bought. Police officer class hold name and badge number. Then theres a parking ticket class that creates the ticket with the information of the other classes then outputs to the similator program.
So heres where I am stuck currently. The "ParkingTicketSimulator.java" is getting an error:
Heres the code for the Simulator which was provided to me by the instructor and does not need to be edited:Quote:
ParkingTicketSimulator.java:24: cannot find symbol
symbol : method patrol(ParkedCar,ParkingMeter)
location: class PoliceOfficer
ParkingTicket ticket = officer.patrol(car, meter);
ParkingMeter class that I wrote. Having trouble aggregating the PoliceOfficer class into here (code in red are the areas in question).Code:public class ParkingTicketSimulator
{
public static void main(String[] args)
{
// Create a ParkedCar object.
// The car was parked for 125 minutes.
ParkedCar car = new ParkedCar("Volkswagen", "1972", "Red",
"147RHZM", 125);
// Create a ParkingMeter object. 60 minutes were purchased.
ParkingMeter meter = new ParkingMeter(60);
// Create a PoliceOfficer object.
PoliceOfficer officer = new PoliceOfficer("Joe Friday",
"4788");
[COLOR="Red"] // Let the officer patrol.
ParkingTicket ticket = officer.patrol(car, meter);[/COLOR]
// Did the officer issue a ticket?
if (ticket != null)
System.out.println(ticket);
else
System.out.println("No crimes committed!");
}
}
If anybody can help it would be greatly appreciated, I am completely confused. Been over the chapter a number of times and it's just not clicking for me. Thanks.Code:
public class ParkingTicket
{
//private String patrol, officer, issuer, badge;
private int fine;
private ParkedCar car, make, year, color, license;
private ParkingMeter time;
[COLOR="red"]private PoliceOfficer officer;[/COLOR]
public ParkingTicket(ParkedCar car, ParkingMeter time)
{
this.make = make;
this.year = year;
this.color = color;
this.license = license;
this.time = time;
[COLOR="red"]PoliceOfficer patrol = new PoliceOfficer(officer);[/COLOR]
}
public int getFine()
{
if(car.getParked() > time.getTimePurchased())
{
fine = 25 + 10*(int)(Math.ceil((double)(car.getParked()-60)/60));
}
else{
fine = 25;
}
return fine;
}
[COLOR="Red"] public PoliceOfficer getPoliceOfficer()
{
return new PoliceOfficer(officer);
}[/COLOR]
//To string
public String toString()
{
//Create a string representing the car information
String str = "\nMake: " + make
+ "\nYear: " + year
+ "\nColor: " + color
+ "\nLicense Plate: " + license
+ "\n\n Amount of Fine: " + fine
+ "Issued by:\n" + officer;
//Return string
return str;
}
}

