-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParkingCharges.java
More file actions
42 lines (29 loc) · 1 KB
/
ParkingCharges.java
File metadata and controls
42 lines (29 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Scanner;
public class ParkingCharges {
public static double calculateCharges(double hours) {
double charge = 2.0;
if (hours > 3) {
charge += Math.ceil(hours - 3) * 0.5;
}
if (charge > 10.0) {
charge = 10.0;
}
return charge;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double hours;
double totalReceipts = 0.0;
System.out.print("Enter hours parked : ");
hours = sc.nextDouble();
while (hours != -1) {
double charge = calculateCharges(hours);
System.out.println("Charge for this customer: $" + charge);
totalReceipts += charge;
System.out.print("\nEnter hours parked (-1 to quit): ");
hours = sc.nextDouble();
}
System.out.println("\nTotal receipts for yesterday: $" + totalReceipts);
sc.close();
}
}