Calculating Parking Fees Here's the challenge description:


  A parking garage charges a $2.00 minimum fee to park for up to three hours.
  The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours.
  The maximum charge for any given 24 hour period is $10.00.
  Assume that no car parks for longer than 24 hours at a time.
  
  Write a Java program that calculates and displays the parking charges for each customer who parked in the garage yesterday.
  Input the number of hours parked for each customer. The number of customers can be fixed using a final constant.
  
  The program should display the charge for the current customer and should calculate and display the running total of the day's receipts.
  Use a method called calculateCharges to determine the charge for each customer.


Here's my code:

import java.text.DecimalFormat;
import java.util.Scanner;

public class Hwk4B {

    public static void main(String[] args) 
    {

        Scanner keyboard = new Scanner(System.in);
        DecimalFormat formatter = new DecimalFormat("$##.00");

        System.out.print("Enter the number of cars parked yesterday: ");
        final int NUMBER_OF_CARS = keyboard.nextInt();

        double hoursParked=0;
        double currentCost=0;   
        double totalCost=0;

        for(int count = 1; count&lt;=NUMBER_OF_CARS; count++)
        {   
            System.out.print("Enter hours parked for car " + count + ": ");
            hoursParked = keyboard.nextDouble();
            currentCost = calculateCharges(hoursParked); //most recent customer
            totalCost+=currentCost; //Running total
        }

        System.out.println("Most recent customer paid: "   +  formatter.format(currentCost));
        System.out.println("Running total of receipts: " + formatter.format(totalCost));

    }

    public static double calculateCharges (double numHours)
    {

        double garageCost = 0;

        if(numHours&lt;=3)
            garageCost = 2;

        else if(numHours&gt;3 &amp;&amp; numHours&lt;=19)
            garageCost = 2.0 + 0.5*(numHours - 3);

        else if (numHours &gt;19)
            garageCost = 10;

        return garageCost;
    }

}
Your code should be as similar to the spec as possible so:

else if (numHours &gt;19)
     garageCost = 10;


Should be removed and you should add:

return Math.min(garageCost, 10)


My final version is:

public static double calculateCharges (double numHours)
{
    if (numHours &lt;= 3)
    {
         return 2;
    }
    double garageCost = 2.0 + 0.5 * (numHours - 3);
    return Math.min(garageCost, 10);
}