Hello, I am doing the famous Parking ticket simulator. I have the whole thing compiling and it works! however, I am out on my calculations. My vehicle is parked for 125 mins, and I paid for 60 minutes. I am being fined for 65 minutes of illegal parking.
The first hour is $25 base fine, and after 120 minutes, $10 should be added. I have something wrong here, as when I run the code, it is adding $25 for the base rate, $20 for time parked. It is either looking at the total time parked as illegal, and charging me as such, or it is charging me $35 (25 for base fine + hourly fine)for the first hour of illegal parking, and $10 for the part hour...Please help, as I have gone through this again and again.
Here is the code: (just the class that has the calculations, I can put the whole thing up, but it is quite large.)
import java.text.DecimalFormat; public class ParkingTicket { private ParkedCar car; private PoliceOfficer officer; private double fine; private int minutes; final double BASE_FINE = 25.0; final double HOURLY_FINE = 10.0; public ParkingTicket(ParkedCar car, PoliceOfficer officer, int minutes) { this.car = car; this.officer = officer; this.minutes = minutes; } public ParkingTicket(ParkingTicket ticket2) { car = ticket2.car; officer = ticket2.officer; fine = ticket2.fine; minutes = ticket2.minutes; } public void calculateFine() { if(car.getMinutesParked() >= 60) { if(car.getMinutesParked() - ParkingMeter.getMinutesPurchased() <= 60) { fine = BASE_FINE; } else { fine = BASE_FINE + (HOURLY_FINE * ((car.getMinutesParked() - ParkingMeter.getMinutesPurchased()) /60)); } } } DecimalFormat decimalformat = new DecimalFormat("#0.00"); public double getFine() { return fine; } public String toString() { String string = car + "\n" + officer + "\n" + "The fine is: \n $" + decimalformat.format(fine) ; return string; } }