-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInterface.java
More file actions
98 lines (84 loc) · 3.02 KB
/
UserInterface.java
File metadata and controls
98 lines (84 loc) · 3.02 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
// --== CS400 File Header Information ==--
// Name: Kairas Mistry
// Email: kbmistry@wisc.edu
// Team: EB
// TA: Keren Chen
// Lecturer: Gary Dahl
// Notes to Grader: <optional extra notes>
import java.util.NoSuchElementException;
import java.util.Scanner;
//This class is the front end portion of the project
public class UserInterface {
private static void options(){
System.out.println("Welcome to the Worldwide Directory.");
System.out.println("What would you like to do?");
// System.out.println("(V)iew current directory");
System.out.println("(C)lear the current directory");
System.out.println("(E)nter a new country");
System.out.println("(A)dd info to an existing country");
System.out.println("(G)et info about a country");
System.out.println("(R)emove a country");
System.out.println("(L)oad default directory");
System.out.println("(Q)uit");
}
public static void main(String[] args) {
StateTable<String, String> map = new StateTable<String, String>();
Scanner sc = new Scanner(System.in);
String input;
String info;
int index = 0;
do {
options();
input = sc.nextLine().substring(0, 1).toLowerCase();
switch(input) {
// case "v": //TODO
// for(int i = 0; i < map.stateTable.size(); i++) {
// System.out.println(map.stateTable);
// }
// break;
case "c":
map.stateTable.clear();
break;
case "e":
System.out.println("Which country would you like add?");
input = sc.nextLine();
map.keyToIndex(input);
break;
case "a":
System.out.println("Which country would you like to add information to?");
input = sc.nextLine();
System.out.println("What information would you like to add?");
info = sc.nextLine();
map.insertInfo(input, info);
break;
case "g":
try {
System.out.println("Which existing country would you like to know about?");
input = sc.nextLine();
System.out.println(map.stateTable.get(input));
}catch(NoSuchElementException e) {
System.out.println(e.getMessage());
}
break;
case "r":
System.out.println("Which existing country would you like to remove?");
input = sc.nextLine();
map.stateTable.remove(input);
break;
case "l":
MapData data=new MapData();
for (int i=0; i<data.size;i++) {
map.stateTable.put(data.getCountry(i), data.getInfo(i));
}
System.out.println("The default directory has been successfully loaded.");
break;
case "q":
break;
default:
System.out.println("The command does not exist");
break;
}
}while(!input.equals("q"));
System.out.println("Thank you for using the Worldwide Directory!");
}
}