-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyBnB.java
111 lines (102 loc) · 3.1 KB
/
MyBnB.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
import java.io.IOException;
import java.sql.*;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
/**
* Handles user interaction with the terminal.
*/
public class MyBnB {
private static ArrayList<String> functions = new ArrayList<String>();
private static Scanner scanner;
public static void main(String[] args) throws ClassNotFoundException, ParseException, SQLException, IOException {
SqlDAO.getInstance().createDatabase("create_database.txt");
scanner = new Scanner(System.in); // Create a Scanner object
functions = new ArrayList<>(Arrays.asList("user/create", "user/delete", "user/show",
"user/review", "user/seereview", "listing/search", "listing/book", "bookings/show", "bookings/completestay",
"bookings/cancel", "listing/create", "listing/remove", "listing/update",
"listing/review", "listing/seereview", "reports", "exit"));
while (handle(selectFunction()))
;
scanner.close();
SqlDAO.deleteInstance();
}
public static boolean handle(String userInput) {
try {
switch (userInput.toLowerCase()) {
case "user/create":
User.registerUser(scanner);
break;
case "user/delete":
User.deleteUser(scanner);
break;
case "user/show":
User.showUsers();
break;
case "user/review":
User.reviewUser(scanner);
break;
case "user/seereview":
User.showUserReviews(scanner);
break;
case "listing/create":
Listing.createListing(scanner);
break;
case "listing/update":
Listing.updateListing(scanner);
break;
case "listing/remove":
Listing.removeListing(scanner);
break;
case "listing/book":
Listing.bookListing(scanner);
break;
case "listing/review":
User.reviewListing(scanner);
break;
case "listing/seereview":
User.showListingReviews(scanner);
break;
case "bookings/show":
User.showBookingsForHost(scanner, -1);
break;
case "bookings/cancel":
User.cancelBooking(scanner);
break;
case "bookings/completestay":
User.completeStay(scanner);
break;
case "listing/search":
Listing.listingSearch(scanner);
break;
case "reports":
Report.report(scanner);
break;
case "exit":
return false;
default:
System.out.println("Invalid operation");
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
public static String selectFunction() {
System.out.println("\nFunctions supported:");
int index = 0;
for (String f : functions) {
System.out.format("%-25s", f);
index++;
if (index % 4 == 0) {
System.out.println();
}
}
System.out.println("\n");
System.out.print("Select a function: ");
String choice = scanner.nextLine();
System.out.println();
return choice;
}
}