-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarTracker.java
More file actions
161 lines (138 loc) · 5.79 KB
/
CarTracker.java
File metadata and controls
161 lines (138 loc) · 5.79 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import java.util.Scanner;
/**
*
* @author Zach
*/
public class CarTracker {
public static Scanner input;
public static MyPriorityQueue pricePQ;
public static MyPriorityQueue mileagePQ;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
CarTracker carTracker = new CarTracker();
pricePQ = new MyPriorityQueue();
mileagePQ = new MyPriorityQueue();
input = new Scanner(System.in);
carTracker.getInput();
}
public void getInput(){
System.out.println("Welcome: ");
System.out.println("1. Add Car");
System.out.println("2. Update Car");
System.out.println("3. Remove Car");
System.out.println("4. Return lowest price car");
System.out.println("5. Return lowest mileage car");
System.out.println("6. Return lowest price car by manufacturer and model");
System.out.println("7. Return lowest mileage car by manufacturer and model");
System.out.println("8. Exit\n");
System.out.println("Enter the number corresponding to the desired operation: ");
int operation = input.nextInt();
while(operation < 1 || operation > 8){
System.out.println("Invalid input: Enter the number corresponding to the desired operation.\n");
operation = input.nextInt();
}
if(operation == 1){
addCar();
} else if (operation == 2){
updateCar();
} else if (operation == 3){
removeCar();
} else if (operation == 4){
returnLowestPriceCar();
} else if (operation == 5){
returnLowestMileageCar();
} else if (operation == 6){
returnLowestPriceCarByMakeAndModel();
} else if (operation == 7){
returnLowestMileageCarByMakeAndModel();
} else {
System.exit(0);
}
}
private void addCar() {
System.out.println("\nPlease enter the following information:\n");
System.out.println("Enter a VIN:");
String VIN = input.next();
System.out.println("Enter the manufacturer:");
String manufacturer = input.next();
System.out.println("Enter the model:");
String model = input.next();
System.out.println("Enter the color:");
String color = input.next();
System.out.println("Enter the price:");
double price = input.nextDouble();
System.out.println("Enter the milage:");
double milage = input.nextDouble();
CarClass newCar = new CarClass(VIN, manufacturer, model, color, price, milage);
mileagePQ.addCarToMileagePQ(newCar);
pricePQ.addCarToPricePQ(newCar);
System.out.println("\nEnter 1 to add another car or 0 to return to the main menu: ");
int userInput = input.nextInt();
if(userInput == 1){
addCar();
} else {
getInput();
}
}
private void updateCar() {
System.out.println("Enter the Vin of the Car you wish to update: ");
String VIN = input.next();
System.out.println("Enter 1 to update the color, 2 to update the price, 3 to update the mileage, and 4 to return to the main menu: ");
int changeNumber = input.nextInt();
if(changeNumber == 1){
System.out.println("Enter the updated Color: ");
String color = input.next();
mileagePQ.changeColor(VIN, color);
pricePQ.changeColor(VIN, color);
} else if(changeNumber == 2){
System.out.println("Enter the updated Price: ");
double price = Double.parseDouble(input.next());
pricePQ.updatePrice(price, VIN);
mileagePQ.updatePrice(price, VIN);
} else if(changeNumber == 3){
System.out.println("Enter the updated Mileage: ");
double milage = input.nextDouble();
pricePQ.updateMilage(milage, VIN);
mileagePQ.updateMilage(milage, VIN);
}
getInput();
}
private void removeCar() {
System.out.println("Please Enter the VIN of the car to be removed: ");
String VIN = input.next();
pricePQ.remove(VIN);
mileagePQ.remove(VIN);
System.out.println("The car with VIN:" + VIN + " has been removed");
getInput();
}
private void returnLowestPriceCar() {
String carInfo = pricePQ.returnLowestPriceCar();
System.out.println(carInfo);
getInput();
}
private void returnLowestMileageCar() {
String carInfo = mileagePQ.returnLowestMilageCar();
System.out.println(carInfo);
getInput();
}
private void returnLowestPriceCarByMakeAndModel() {
System.out.println("Enter the manufacturer of the car:");
String manufacturer = input.next();
System.out.println("Enter the model of the car:");
String model = input.next();
String carInfo = pricePQ.returnLowestMilageCarByManufacturerAndModel(manufacturer.toLowerCase(), model.toLowerCase());
System.out.println(carInfo);
getInput();
}
private void returnLowestMileageCarByMakeAndModel() {
System.out.println("Enter the manufacturer of the car:");
String manufacturer = input.next();
System.out.println("Enter the model of the car:");
String model = input.next();
String carInfo = pricePQ.returnLowestPriceCarByManufacturerAndModel(manufacturer.toLowerCase(), model.toLowerCase());
System.out.println(carInfo);
getInput();
}
}