I'll try to keep this short.
I need to access ParkedCar.minutesParked and ParkingMeter.minutesPurchased from ParkingTicket.calculateFine() and I keep getting an error that the variable isn't visable. I understand why it's happening, the variables are set to private. But, I'm working off of a UML, so they have to stay that way.
Any suggestions would be great.
public class ParkedCar { private String make; private String model; private String color; private String licenseNumber; private int minutesParked; public ParkedCar(String mk, String mod, String col, String lic, int min) { make = mk; model = mod; color = col; licenseNumber = lic; minutesParked = min; } public ParkedCar(ParkedCar car2) { make = car2.make; model = car2.model; color = car2.color; licenseNumber = car2.licenseNumber; minutesParked = car2.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 getLicenseNumber() { return licenseNumber; } public void setLicenseNumber(String licenseNumber) { this.licenseNumber = licenseNumber; } public int getMinutesParked() { return minutesParked; } public void setMinutesParked(int minutesParked) { this.minutesParked = minutesParked; } public String toString() { String str = "Car Data:" + "\nMake: " + make + "\nModel: " + model + "\nColor: " + color + "\nLicense Number: " + licenseNumber + "\nMinutes Parked: " + minutesParked; return str; } }
public class ParkingMeter { private int minutesPurchased; public ParkingMeter(int m) { minutesPurchased = m; } public int getMinutesPurchased() { return minutesPurchased; } public void setMinutesPurchased(int minutesPurchased) { this.minutesPurchased = minutesPurchased; } }
public class ParkingTicket { private ParkedCar car; private PoliceOfficer officer; private double fine; private int minutes; public double BASE_FINE = 25.0; public double HOURLY_FINE = 10.0; public ParkingTicket(ParkedCar aCar, PoliceOfficer anOfficer, int min) { car = new ParkedCar(aCar); officer = new PoliceOfficer(anOfficer); minutes = min; } public ParkingTicket(ParkingTicket ticket2) { car = ticket2.car; officer = ticket2.officer; minutes = ticket2.minutes; } //This is where I'm having issues public void calculateFine() { if(ParkedCar.minutesParked - ParkingMeter.minutesPurchased <= 60) fine = BASE_FINE; else fine = BASE_FINE + (HOURLY_FINE * ((ParkedCar.minutesParked - ParkingMeter.minutesPurchased) / 60 )); } 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 double getBASE_FINE() { return BASE_FINE; } public void setBASE_FINE(double bASE_FINE) { BASE_FINE = bASE_FINE; } public double getHOURLY_FINE() { return HOURLY_FINE; } public void setHOURLY_FINE(double hOURLY_FINE) { HOURLY_FINE = hOURLY_FINE; } public String toString() { String str = "Minutes Parked: " + minutes; return str; } }