Answer to Question #274309 in Java | JSP | JSF for Uzumaki

Question #274309

(Parking Charges)A parking garagecharges 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-hourperiod is $10.00. Assume that no car parks for longer than 24 hours at a time. Write an application that calculates and displays the parking charges for each customer who parked in the garage yesterday. You should enter the hours parked for each customer. The program should display the charge for the current customer and should calculate and display the running total of yesterday’s receipts. It should use the method calculateCharges to determine the charge for each customer.





1
Expert's answer
2021-12-02T00:35:05-0500
public class Main {

    public static double[] calculateCharges(double[] hours) {
        double[] charges = new double[hours.length];
        for (int i = 0; i < hours.length; i++) {
            if (hours[i] <= 3) {
                charges[i] = 2;
            } else if (hours[i] > 18) {
                charges[i] = 10;
            } else {
                charges[i] = 2;
                if (hours[i] - (int) hours[i] > 0) {
                    charges[i] += 0.5;
                }
                charges[i] += ((int) hours[i] - 3) * 0.5;
            }
        }
        return charges;
    }

    public static void main(String[] args) {
        double[] hours = {24, 2.5, 3, 3.5, 20.5, 21, 20, 19, 19.5, 6, 13, 18};
        double total = 0;
        double[] charges = calculateCharges(hours);
        for (int i = 0; i < charges.length; i++) {
            System.out.println("Customer " + (i + 1) + " " + charges[i]);
            total += charges[i];
        }
        System.out.println("Total: " + total);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS