Repository navigation
Expand file tree
/
Copy pathCodified.java
More file actions
64 lines (51 loc) · 2.29 KB
/
Copy pathCodified.java
File metadata and controls
64 lines (51 loc) · 2.29 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
package task_2;
import java.sql.SQLException;
import java.util.Scanner;
public class Codified {
public static void main(String[] args) throws SQLException {
// flag to change state when program termination is initiated
boolean running = true;
// initiate dbHandler session (initiate connection, initiate access)
DBHandler db = new DBHandler();
// register user inputs
Scanner inputMonitor = new Scanner(System.in);
// overall program loop
while (running) {
// menu options displayed in terminal
System.out.println("\nWelcome to codified!");
System.out.println("Please select your function from the menu below:");
System.out.println("'1' to ADD a book to bookBASE.");
System.out.println("'2' to UPDATE a book in bookBASE.");
System.out.println("'3' to DELETE a book from bookBASE.");
System.out.println("'4' to SEARCH a book in bookBASE.");
System.out.println("'5' to VIEW all bookBASE records.");
System.out.println("'0' to quit bookBASE.");
// register user input to determine loop branch
String userInput = inputMonitor.next();
// enhanced switch for all branching functionality
switch (userInput) {
// quit case
case "0" -> {
System.out.println("\nSession Terminated");
System.out.println("Bye.");
running = false; // state changed, loop will not renew
}
// record entry branch
case "1" -> db.createRecord();
// record update branch
case "2" -> db.updateRecord();
// record delete branch
case "3" -> db.deleteRecord();
// record search branch
case "4" -> db.searchRecord();
// view all records branch
case "5" -> System.out.println(db.toStringDB());
// handling invalid inputs
default -> System.out.println("\nInvalid input! Please submit an input from the list below.");
}
}
// close connection, close Scanner
db.closeConnection();
inputMonitor.close();
}
}