0

I am new to coding and was wondering how would I go about coding this fine? I am pretty sure I am going about it the wrong coding way if anyone could help that would be greatly appreciated.

Below is what is expected:

The fine will be a dollar value, which is a double data type. ParkingTicket will not have a double-typed fine variable. Instead, it calculates the fine on-demand, using the minutesPaid and minutesParked variables. Impark levies a flat-rate fine of $20 (always), plus $10 aggravated penalties for every whole hour (60 minutes) parked beyond the paid amount. As a Canadian institution, Impark is also obligated to add the 5% Goods and Services Tax surcharge. A surcharge is multiplied after all other sums have been calculated. You are responsible for producing the result of this calculation in calculateFine().

So far this is what I have, :

public static double calculateFine()
{
    double meterMinutesPaidWithTax = 20*0.05;
    double meterMinutesPaid = 20;
    double pentalty = 10;
    double tax = 0.05;
    double overParked = (carMinutesParked+=1);



    if(carMinutesParked<=carMinutesParked){
        return meterMinutesPaidWithTax = meterMinutesPaidWithTax+meterMinutesPaid;
    }
    else if(carMinutesParked>overParked){
        return meterMinutesPaid = (meterMinutesPaid + pentalty)*tax+(meterMinutesPaid + pentalty);
    }
    else{
        return meterMinutesPaidWithTax;
    }
}
Tre
  • 37
  • 8
  • 3
    Well `if(carMinutesParked<=carMinutesParked){` is always true. Because `59` is equal to `59`. – Elliott Frisch Oct 28 '15 at 22:39
  • 1
    Never use double for representing currency. Use [`BigDecimal`](https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html) instead. For reasons why, see ["Why not use Double or Float to represent currency?"](https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency/) – Philipp Oct 28 '15 at 22:43
  • Pass the number of minutes over the allowed time (carMinutesParked ) in as an argument, the will help you calculate your fine amount. Use longs or Big Decimals, not Doubles as pointed out already. – MikeJ Oct 28 '15 at 22:49

0 Answers0