In: Computer Science
Write a Java Program.A parking garage charges a $3.00 minimum fee to park for up to three hours. The garage charges an additional $0.75 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $12.00 per day. Write an application that calculates and displays the parking charges for all customers 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 grand total of yesterday’s receipts. Use a sentinel controlled loop.
ParkingChargesBill.java
import java.util.Scanner;
public class ParkingChargesBill {
public static void main(String[] args) {
Scanner scan = new
Scanner(System.in);
System.out
.println("Enter the hours parked for customer
(-1 to quit): ");
int hours = scan.nextInt();
double totalCharges = 0;
while (hours != -1) {
double charges =
0;
if (hours >
24) {
charges = 12 * hours / 24;
hours = hours % 24;
}
if (hours >
3) {
charges = charges + 3;
hours = hours - 3;
charges = charges + 0.75 * hours;
} else {
charges = charges + 3;
}
System.out.println("Parking charges for current customer is "
+ charges);
totalCharges =
totalCharges + charges;
System.out
.println("Enter the hours
parked for customer (-1 to quit): ");
hours =
scan.nextInt();
}
System.out.println("Total Parking
chrages for all customers is "
+ totalCharges);
}
}
Output:
Enter the hours parked for customer (-1 to quit):
25
Parking charges for current customer is 15.0
Enter the hours parked for customer (-1 to quit):
12
Parking charges for current customer is 9.75
Enter the hours parked for customer (-1 to quit):
2
Parking charges for current customer is 3.0
Enter the hours parked for customer (-1 to quit):
5
Parking charges for current customer is 4.5
Enter the hours parked for customer (-1 to quit):
-1
Total Parking chrages for all customers is 32.25