-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCarJSON.java
More file actions
112 lines (94 loc) · 3.1 KB
/
Copy pathtestCarJSON.java
File metadata and controls
112 lines (94 loc) · 3.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import java.util.ArrayList;
import java.util.Scanner;
import java.util.UUID;
public class testCarJSON {
private Scanner scanner;
public testCarJSON() {
scanner = new Scanner(System.in);
}
public void play() {
Cars cars = Cars.getInstance();
System.out.println("***** Current Cars *****");
displayCars();
while(addCar()) {
cars.addCar(getCar());
}
System.out.println("***** Cars Now *****");
displayCars();
cars.logout();
}
protected Car getCar() {
UUID carID = UUID.randomUUID();
CarType type = getCarType();
int capacity = getInt("Capacity");
double price = getDouble("Price");
String pickUpLocation = getField("Pick Up");
String dropOffLocation = getField("Drop Off");
Reservation carReservation = getReservation();
return new Car(carID, type, capacity, price, pickUpLocation, dropOffLocation, carReservation);
}
protected String getField(String prompt) {
System.out.print(prompt + ": ");
return scanner.nextLine();
}
protected int getInt(String prompt) {
System.out.print(prompt + ": ");
int age = scanner.nextInt();
scanner.nextLine();
return age;
}
protected double getDouble(String prompt) {
System.out.print(prompt + ": ");
double age = scanner.nextDouble();
scanner.nextLine();
return age;
}
protected CarType getCarType() {
System.out.println("Car Types: ");
for (int i = 0; i < CarType.values().length; i++) {
System.out.println(i + ": " + CarType.values()[i]);
}
System.out.println("Choose a number: ");
int rand = scanner.nextInt();
scanner.nextLine();
switch(rand) {
case 0:
return CarType.ECONOMY;
case 1:
return CarType.COMPACT;
case 2:
return CarType.SEDAN;
case 3:
return CarType.LUXURY;
case 4:
return CarType.MINIVAN;
case 5:
return CarType.SUV;
}
return CarType.SEDAN;
}
protected Reservation getReservation() {
Date sDate = new Date(getField("Date (mm/dd/yy"));
Date eDate = new Date(getField("Date (mm/dd/yy"));
Time sTime = new Time(getField("Time (hh:mm a/pm"));
Time eTime = new Time(getField("Time (hh:mm a/pm"));
return new Reservation(sDate, eDate, sTime, eTime);
}
protected boolean addCar() {
System.out.print("Would you like to add a new car? (Y or N): ");
String input = scanner.nextLine();
if(input.toLowerCase().trim().equals("y")) return true;
return false;
}
protected void displayCars() {
Cars cars = Cars.getInstance();
ArrayList<Car> carList = cars.getCars();
for (Car c: carList) {
System.out.println(c.toString());
}
}
public static void main(String[] args) {
testCarJSON test = new testCarJSON();
test.play();
}
}