-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCovidTracker.java
More file actions
101 lines (98 loc) · 3.3 KB
/
Copy pathCovidTracker.java
File metadata and controls
101 lines (98 loc) · 3.3 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
99
100
101
// --== CS400 File Header Information ==--
// Name: Elaina Timmerman
// Email: eltimmerman@wisc.edu
// Team: BA
// TA: Bri
// Lecturer: Gary Dahl
// Notes to Grader: none
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class CovidTracker extends HashTableMap {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
HashTableMap map = new HashTableMap(10);
run(scnr, map);
}
public static void run(Scanner scnr, HashTableMap map) {
System.out.println(
"Welcome to UW-Madison COVID Tracker!\nCommands:\nF: Insert File\nI: Insert\nG: Get object\nS: Size \nL: Lookup \nR: Remove object\nC: Clear\nQ: Quit");
String commands = scnr.nextLine().trim().toLowerCase();
boolean exit = false;
while (!exit) {
System.out.print("Enter a command:");
commands = scnr.nextLine().trim().toLowerCase();
switch (commands) {
case "s":
System.out.println(map.size());
break;
case "i": // insert
System.out.println("Enter student ID:");
int id1 = scnr.nextInt();
System.out.println("Enter student location:");
String location = scnr.next();
System.out.println("Enter student status:");
String status = scnr.next();
Student object = new Student(id1, location, status);
map.put(id1, object);
System.out.println("Student is added");
break;
case "r": // remove
System.out.println("Enter student ID:");
int id = scnr.nextInt();
try {
System.out.print(map.remove(id) + "is removed");
} catch (NullPointerException e) {
System.out.println("ID is not in map");
continue;
}
break;
case "f": //file input
try {
System.out.println("Type file name:");
String file = scnr.next();
File input = new File(file);
FileReader readFile = new FileReader(map, input);
}catch (FileNotFoundException e) {
System.out.println("File cannot be found.");
}
break;
case "m": // menu
System.out.println(
"Commands:\nI: Insert\nG: Get object\nS: Size\nF: Insert File\nL: Lookup \nR: Remove object\nC: Clear\nQ: Quit");
break;
case "c": // clear
map.clear();
System.out.println("Map is cleared");
break;
case "g": // get student object
System.out.println("Enter student ID:");
int id2 = scnr.nextInt();
try {
System.out.print(map.get(id2));
} catch (NoSuchElementException e) {
System.out.println("ID is not in map");
continue;
}
break;
case "l": // lookup
System.out.println("Enter student ID:");
int id3 = scnr.nextInt();
try {
System.out.println(map.containsKey(id3));
} catch (NoSuchElementException e) {
System.out.println("ID is not in map");
continue;
}
break;
case "q": // quit
System.out.println("Bye!");
exit = true;
break;
}
}
scnr.close();
}
}