I am doing a Parking Ticket Simulator for a Java class.
I am using NetBeans 6.8 and I keep getting error messages in my code. The two most prominent error messages are: '{' is expected and "non-static variable this cannot be referenced from a static context".
I have e-mailed my instructor, but I have not got any word back yet. If anyone could help me, it would be greatly appreciated.
Note: I did put "static" before class, but I have read from numerous sites that no output will be displayed.
Here is my code thus far, also if see any other errors or nuances that may pop up, please let me know.
Thank you for your help!
public static class ParkedCar(){ private String make; private String model; private String color; private String license; private int minutesParked; public ParkedCar(String make, String model, String color, String license, int minutesParked) { this.make = make; this.model = model; this.color = color; this.license = license; this.minutesParked = minutes; } public ParkedCar(ParkedCar car2){ make = car2.make; model= car2.model; color = car2.color; license = car2.license; minutesParked = car2.minutesParked; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public String getLicense() { return license; } public void setLicense(String license) { this.license = license; } public String getMake() { return make; } public void setMake(String make) { this.make = make; } public int getMinutesParked() { return minutesParked; } public void setMinutes(int minutesParked) { this.minutesParked = minutesParked; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } @Override public String toString(){ String string = "Car Data: \n Make: " + make + "\n Model: " + model + "\n Color: " + color + "\n License Plate: " + license + "\n Minutes Parked: " + minutesParked; return string; } } public static class ParkingMeter(){ private int minutesPurchased; public ParkingMeter(int minutesPurchased) { this.minutesPurchased = minutesPurchased; } public void setMinutesPurchased(int minutesPurchased){ minutesPurchased = minutesPurchased; } public int getMinutesPurchased(){ return minutesPurchased; } } public static class ParkingTicket(){ private ParkedCar car; private PoliceOfficer officer; private double fine; private int minutes; double BASE_FINE = 25.0; double HOURLY_FINE = 10.0; public ParkingTicket(ParkedCar car, PoliceOfficer officer, double fine, int minutes) { this.car = car; this.officer = officer; this.fine = fine; this.minutes = minutes; } public ParkingTicket(ParkingTicket ticket2){ car = ticket2.car; officer = ticket2.officer; fine = ticket2.fine; minutes = ticket2.minutes; } public void calculateFine(){ if(ParkedCar.minutesParked - ParkingMeter.minutesPurchased <= 60) fine = BASE_FINE; else fine = BASE_FINE + (HOURLY_FINE * ((ParkedCar.minutesParked - ParkingMeter.minutesPurchased) / 60 )); } public double getBASE_FINE() { return BASE_FINE; } public void setBASE_FINE(double BASE_FINE) { this.BASE_FINE = BASE_FINE; } public double getHOURLY_FINE() { return HOURLY_FINE; } public void setHOURLY_FINE(double HOURLY_FINE) { this.HOURLY_FINE = HOURLY_FINE; } public ParkedCar getCar() { return car; } public void setCar(ParkedCar car) { this.car = car; } 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 PoliceOfficer getOfficer() { return officer; } public void setOfficer(PoliceOfficer officer) { this.officer = officer; } } public static class PoliceOfficer(){ private String name; private String badgeNumber; public PoliceOfficer(String name, String badgeNumber) { this.name = name; this.badgeNumber = badgeNumber; } public PoliceOfficer(PoliceOfficer officer2){ name = officer2.name; badgeNumber = officer2.badgeNumber; } public Patrol(ParkedCar car, ParkingMeter meter){ ParkingTicket(); } @Override public String toString(){ String string = "Officer Data: \n Name: " + name + "\n Badge Number: " + badgeNumber + "\n Minutes Illegally Parked: " + (ParkedCar.minutesParked - ParkingMeter.minutesPurchased) + "Fine: $" + ParkingTicket.fine; return string; }