-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarWash.java
More file actions
57 lines (48 loc) · 1.9 KB
/
Copy pathCarWash.java
File metadata and controls
57 lines (48 loc) · 1.9 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.Scanner;
public class CarWash {
private String carType;
private String washSelection;
private double amountCharge;
public CarWash(String c, String w, double a) {
carType = c;
washSelection = w;
amountCharge = a;
}
public void setCarType(String c) {carType = c;}
public void setWashSelection(String w) {washSelection = w;}
public void setAmountCharge(double a) {amountCharge = a;}
//getters
public String getCarType() {return carType;}
public String getWashSelection() {return washSelection;}
public double getAmountCharge() {return amountCharge;}
//printer
public String toString() {
return "\nCar Type : "+getCarType()+"\nWash Selection : "+getWashSelection()+"\nAmount Charge : "+getAmountCharge();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Scanner num = new Scanner(System.in);
String carType;
String washSelection;
double amountCharge, totalAmount=0;
Queue qCarWash = new Queue();
Queue temp = new Queue();
for(int i=0;i<2;i++) {
System.out.println("\nInsert car type :");
carType = sc.next();
System.out.println("Insert type of wash :");
washSelection = sc.next();
System.out.println("Insert amount charge :");
amountCharge = num.nextDouble();
CarWash cw = new CarWash(carType, washSelection, amountCharge);
qCarWash.enqueue(cw);
}
while(!qCarWash.isEmpty()) {
CarWash c = (CarWash) qCarWash.dequeue();
totalAmount += c.getAmountCharge();
temp.enqueue(c);
}
System.out.println("Total amount of charges : RM"+totalAmount);
sc.close();num.close();
}
}