简体   繁体   中英

calculating a fine and addtional fine java method error

I have this problem I need to solve, I made a method to check if the parkingTime of a car is expired, here is the code

private boolean isParkingTimeExpired(ParkedCar car, ParkingMeter meter) {
    if(car.getNumberOfMinutesParked() > meter.getNumberOfPurchasedMinutes()) {
        return true;
    } else {
        return false;
    }     
}        

private double calculateFine(ParkedCar car, ParkingMeter meter) {
    double totalFine = 0;
    if(isParkingTimeExpired() == true) {
        totalFine = 20;
    }
}

I am told to make a method that will check if the parking time is expired and if so calculate the fine which is $20 per hour, and another $20 for every other additional hour. Now two things, when I try to call the method isParkingTimeExpired to check if time is expired it gives me an error saying method cannot be applied to given types, found no arguments, reason: actual and formal arguments differ in length. Why is this like that? I havent made much progress because I am lost trying to figure out the calculation and also why I cant call on the previous method. Any help is appreciated!

The issue is that you are calling isParkingTimeExpired() but not passing it any arguments in your second if statement.

In your method signature for isParkingTimeExpired it is expecting a ParkedCar object and ParkingMeter object (see below).

private boolean isParkingTimeExpired(ParkedCar car, ParkingMeter meter){

In order to call it correctly, you must pass it the required arguments like this: isParkingTimeExpired(car, meter);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM