-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectCh3App.java
More file actions
67 lines (58 loc) · 1.85 KB
/
ProjectCh3App.java
File metadata and controls
67 lines (58 loc) · 1.85 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
package gr.aueb.cf.ch10.projects;
import java.util.Scanner;
public class ProjectCh3App {
final static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
boolean quit = false;
String response;
do {
printMenu();
response = getChoice();
try {
if (response.matches("[qQ]")) {
quit = true;
} else {
printOnChoice(response);
}
} catch (IllegalArgumentException e) {
System.out.println("Invalid Choice");
}
} while (!quit);
}
public static void printMenu(){
System.out.println("Please select on of the following: ");
System.out.println("1. Insert ");
System.out.println("2. Update ");
System.out.println("3. Delete ");
System.out.println("4. Select ");
System.out.println("5. Q or q to Quit ");
}
public static String getChoice() {
return in.nextLine().trim();
}
public static void printOnChoice(String s) throws IllegalArgumentException {
int choice;
try {
choice = Integer.parseInt(s);
switch (choice) {
case 1:
System.out.println("1. Insert ");
break;
case 2:
System.out.println("2. Update ");
break;
case 3:
System.out.println("3. Delete ");
break;
case 4:
System.out.println("4. Select ");
break;
default:
throw new IllegalArgumentException();
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
throw e;
}
}
}