-
Notifications
You must be signed in to change notification settings - Fork 0
/
TodoView.java
426 lines (396 loc) · 16.6 KB
/
TodoView.java
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
package view;
import controller.Controller;
import model.TodoModel;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
public class TodoView {
BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
Controller controller;
public TodoView(Controller controller){
this.controller=controller;
}
public void displayTodo() {
controller.display();
}
public void addTodo(String filepath) throws IOException, InterruptedException {
String idCar = null;
String plateNumber = null;
String brand = null;
String color = null;
String seat = null;
String transmition = null;
String cost = null;
System.out.println("Please Input Data");
while(true) {
System.out.print("Input 3 Digits ID Car: ");
idCar = scanner.readLine();
int idCarInt = 0;
try {
idCarInt = Integer.parseInt(idCar);
} catch (NumberFormatException e) {
System.out.println();
System.out.println("Use Number Only");
continue;
}
var dataTemp = controller.find(idCarInt);
if (dataTemp != null) {
System.out.println("This ID Car Has Already Taken");
}else{
while (true) {
System.out.print("Input Plate Number: ");
plateNumber = scanner.readLine();
var dataTemp2 = controller.findPlate(plateNumber);
if (dataTemp2 != null) {
System.out.println("This Plate Number Has Already Taken");
} else {
break;
}
}
break;
}
}
if (!plateNumber.isEmpty() || !idCar.isEmpty()){
System.out.print("Input Brand Name: ");
brand = scanner.readLine();
if (brand.isEmpty()){
brand = "-";
}
System.out.print("Input Color Type: ");
color = scanner.readLine();
if (color.isEmpty()){
color = "-";
}
System.out.print("Input Seat Size: ");
seat = scanner.readLine();
if (seat.isEmpty()){
seat = "-";
}
System.out.println("Information");
System.out.println("1. Manual");
System.out.println("2. Matic");
System.out.println("Please Input Number");
System.out.print("Input Transmition Type: ");
String trans = (scanner.readLine());
if (trans.equals("1")) {
transmition = "Manual";
} else if (trans.equals("2")) {
transmition = "Matic";
} else {
transmition = "-";
}
System.out.print("Input Cost per day: ");
cost = scanner.readLine();
if (cost.isEmpty()){
cost = "-";
}
controller.insert(filepath, idCar, plateNumber, brand, color, seat, transmition, cost);
}else {
System.out.println("Error: Input cannot be Continued");
}
}
public void deleteTodo(String filePath) throws IOException{
System.out.print("Input 3 Digits ID Car: ");
String id = "1" + scanner.readLine();
int idCar = Integer.parseInt(id);
System.out.println();
controller.delete(filePath, idCar);
}
public void find() throws IOException{
System.out.println("=============Search By=============");
System.out.println("1. ID Car");
System.out.println("2. Plate Number");
System.out.println("3. Brand");
System.out.println("4. Color");
System.out.println("5. Seat");
System.out.println("6. Transmition");
System.out.println("7. Maximum Cost");
System.out.println("0. Exit");
System.out.println();
System.out.print("Your Input: ");
String input = scanner.readLine();
if (input.equals("1")) {
while (true) {
System.out.print("Input 3 Digits ID Car: ");
try {
int key = Integer.parseInt(scanner.readLine());
System.out.println();
TodoModel findKey = controller.find(key);
if (findKey != null) {
System.out.println("\t\t(((Data Has Found)))");
System.out.println();
System.out.println("ID Car" + "\tPlate Number" + "\tBrand" + "\tColor" +
"\tSeat Size" + "\tTransmition Type" + "\tCost per day");
findKey.display();
} else {
System.out.println("Data Not Found");
System.out.println();
}
break;
}catch (NumberFormatException e) {
System.out.println();
System.out.println("Use Number Only");
}
}
} else if (input.equals("2")) {
System.out.print("Input Plate Number: ");
String key = scanner.readLine();
System.out.println();
TodoModel findKey = controller.findPlate(key);
if (findKey != null) {
System.out.println("\t\t(((Data Has Found)))");
System.out.println();
System.out.println("ID Car" + "\tPlate Number" + "\tBrand" + "\tColor" +
"\tSeat Size" + "\tTransmition Type" + "\tCost per day");
findKey.display();
} else {
System.out.println("Data Not Found");
}
} else if (input.equals("3")) {
System.out.print("Input Brand: ");
String brand = scanner.readLine();
System.out.println();
System.out.println("ID Car" + "\tPlate Number" + "\tBrand" + "\tColor" +
"\tSeat Size" + "\tTransmition Type" + "\tCost per day");
controller.findBrand(brand);
}else if (input.equals("4")) {
System.out.print("Input Color: ");
String color = scanner.readLine();
System.out.println();
System.out.println("ID Car" + "\tPlate Number" + "\tBrand" + "\tColor" +
"\tSeat Size" + "\tTransmition Type" + "\tCost per day");
controller.findColor(color);
} else if (input.equals("5")) {
System.out.print("Input Seat: ");
String seat = scanner.readLine();
System.out.println();
System.out.println("ID Car" + "\tPlate Number" + "\tBrand" + "\tColor" +
"\tSeat Size" + "\tTransmition Type" + "\tCost per day");
controller.findSeat(seat);
} else if (input.equals("6")) {
System.out.println("Information");
System.out.println("1. Manual");
System.out.println("2. Matic");
System.out.println("Please Input Number");
System.out.print("Input Transmition: ");
String trans = (scanner.readLine());
if (trans.equals("1")) {
trans = "Manual";
} else if (trans.equals("2")) {
trans = "Matic";
} else {
System.out.println("Eror: Input Invalid");
return;
}
System.out.println();
System.out.println("ID Car" + "\tPlate Number" + "\tBrand" + "\tColor" +
"\tSeat Size" + "\tTransmition Type" + "\tCost per day");
controller.findTrans(trans);
} else if (input.equals("7")) {
System.out.print("Input Maximum Cost: ");
String cost = scanner.readLine();
System.out.println();
System.out.println("ID Car" + "\tPlate Number" + "\tBrand" + "\tColor" +
"\tSeat Size" + "\tTransmition Type" + "\tCost per day");
controller.findCost(cost);
} else {
System.out.println("Eror: Input Invalid");
}
}
public void update(){
}
public void developer(String filePath) throws IOException, InterruptedException {
while (true) {
System.out.println("---------------------------------------");
System.out.println(" NyewaYuk! |");
System.out.println(" List of Options |");
System.out.println("1. View |");
System.out.println("2. Add |");
System.out.println("3. Delete |");
System.out.println("4. Find |");
System.out.println("0. Exit |");
System.out.println("---------------------------------------");
System.out.print("Input Option Number: ");
String pilihan = scanner.readLine();
System.out.println();
if (pilihan.equals("1")){
for (int i = 0; i <= 35; i++) {
System.out.print("-");
Thread.sleep(50);
System.out.print("_");
Thread.sleep(50);
i++;
}
System.out.println();
displayTodo();
}else if (pilihan.equals("2")){
System.out.println();
addTodo(filePath);
}else if (pilihan.equals("3")){
deleteTodo(filePath);
}else if (pilihan.equals("4")){
find();
}else if (pilihan.equals("0")){
break;
}else {
System.out.println("Error: Input Invalid");
}
}
}
public void addCart() throws IOException {
boolean exit = false;
while (!exit){
System.out.print("Input 3 Digits ID Car: ");
String id = "1" + scanner.readLine();
int idCarKey = Integer.parseInt(id);
TodoModel data = controller.find(idCarKey);
if (data != null){
System.out.println("Data Found");
var isHave = controller.addCart(data);
if (isHave != null){
System.out.println(data.car.getIdCar() + " Has Already in Cart");
}else {
System.out.println("Success Add to Cart");
}
}else {
System.out.println("Data not Found");
}
while (true){
System.out.println("provide input once more?(y/n) ");
String again = scanner.readLine();
if (again.equalsIgnoreCase("y")){
break;
} else if (again.equalsIgnoreCase("n")) {
exit = true;
break;
}else {
System.out.println("Error: Input Invalid");
}
}
}
}
public void viewCart(){
List<TodoModel> cart = controller.getCart();
if (cart !=null){
System.out.println("ID Car"+"\tPlate Number"+"\tBrand"+"\tColor"+
"\tSeat Size"+"\tTransmition Type"+"\tCost per day");
for (TodoModel data : cart){
data.display();
}
System.out.println();
}else {
System.out.println("Cart is Empty");
}
}
public void deleteCart(){
boolean dataCart = controller.deleteCart();
if (dataCart){
System.out.println("Cart has Deleted");
}else {
System.out.println("Cart is Empty");
}
}
public void receiptUser() throws IOException {
List <TodoModel> cart = controller.getCart();
if(!cart.isEmpty()){
int costAll = 0;
for (TodoModel data : cart){
costAll += Integer.parseInt(data.car.getCost());
}
System.out.println("ID Car"+"\tPlate Number"+"\tBrand"+"\tColor"+
"\tSeat Size"+"\tTransmition Type"+"\tCost per day");
for (TodoModel data : cart){
data.display();
}
System.out.println();
System.out.print("Input The Number of Days: ");
int day = Integer.parseInt(scanner.readLine());
costAll = costAll*day;
System.out.println();
System.out.println("Number of Day : " + day);
System.out.println("Total Cost : " + costAll);
}else {
System.out.println("Cart is Empty");
}
}
public void user() throws InterruptedException, IOException {
while (true) {
System.out.println("---------------------------------------");
System.out.println(" NyewaYuk! |");
System.out.println(" List of Options |");
System.out.println("1. View Car List |");
System.out.println("2. Find Data |");
System.out.println("3. Add to Cart |");
System.out.println("4. View Cart |");
System.out.println("5. Delete Cart |");
System.out.println("6. Payment Receipt |");
System.out.println("0. Exit |");
System.out.println("---------------------------------------");
System.out.print("Input Option Number: ");
String pilihan = scanner.readLine();
System.out.println();
if (pilihan.equals("1")){
for (int i = 0; i <= 35; i++) {
System.out.print("-");
Thread.sleep(50);
System.out.print("_");
Thread.sleep(50);
i++;
}
System.out.println();
displayTodo();
}else if (pilihan.equals("2")){
System.out.println();
find();
}else if (pilihan.equals("3")){
System.out.println();
addCart();
}else if (pilihan.equals("4")){
System.out.println();
viewCart();
}else if (pilihan.equals("5")){
System.out.println();
deleteCart();
}else if (pilihan.equals("6")){
System.out.println();
receiptUser();
break;
}else if (pilihan.equals("0")){
break;
}else {
System.out.println("Error: Input Invalid");
}
}
}
public void init() throws IOException, InterruptedException {
//change this path to mydata.csv path location
String filePath = "C:/Users/USER/IdeaProjects/CarRental/src/mydata.csv";
if(controller.readCsv(filePath)){
System.out.println("SUCCESS READ DATA");
}
System.out.println("==============Welcome in===============");
System.out.println("===============NyewaYuk!===============");
System.out.println();
while (true){
System.out.println(" Please Choose! ");
System.out.println(" (0)User or (1)Developer ");
System.out.println("---------------------------------------");
System.out.println();
System.out.print("Input Option Number: ");
String pil = scanner.readLine();
if (pil.equals("0")){
user();
break;
} else if (pil.equals("1")) {
developer(filePath);
break;
}else {
System.out.println("Error: Input Invalid");
}
}
System.out.println("---------------------------------------");
System.out.println(" We Are Here For U |");
System.out.println("---------------------------------------");
}
}