-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCovidDriver.java
More file actions
110 lines (108 loc) · 3.49 KB
/
Copy pathCovidDriver.java
File metadata and controls
110 lines (108 loc) · 3.49 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
102
103
104
105
106
107
108
109
110
// --== CS400 File Header Information ==--
// Name: Neel Murthy
// Email: nmurthy@wisc.edu
// Team: BA
// TA: Bri
// Lecturer: Gary Dahl
// Notes to Grader: none
import java.util.Scanner;
import java.util.NoSuchElementException;
import java.io.*;
import java.nio.file.*;
import java.util.InputMismatchException;
public class CovidDriver {
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
HashTableMap m=new HashTableMap();
try {
run(input, m);
}
catch(InputMismatchException e1)
{
System.out.println("Invalid Input");
}
}
public static void run(Scanner input, HashTableMap m) throws InputMismatchException{
System.out.println("*****************Welcome to the UW Covid DataBase*****************");
System.out.println(" Please Select From The Following Options: ");
System.out.println("**********************************************************************");
boolean exit = false;
while (!exit) {
System.out.println(
"----------------------------------------------------------------------------------------------------------");
System.out.println("Enter 0 to exit the application.");
System.out.println("Enter 1 to search for a student.");
System.out.println("Enter 2 to remove a student from the database.");
System.out.println("Enter 3 to add a new student to the database.");
System.out.println("Enter 4 to clear the database.");
System.out.println("Enter 5 to enter a file of students into the database.");
System.out.println(
"----------------------------------------------------------------------------------------------------------");
int choice = input.nextInt();
switch (choice) {
case 0:
exit = true;
break;
case 1:
System.out.println("Enter an ID to search for a student: ");
int id=input.nextInt();
try {
System.out.println(m.get(id).toString());
}
catch(NoSuchElementException e1)
{
System.out.println("Invalid ID");
continue;
}
break;
case 2:
System.out.println("Enter an ID to remove a student: ");
int rmID=input.nextInt();
try {
System.out.println(m.remove(rmID).toString()+" has been removed.");
}
catch(NullPointerException e1)
{
System.out.println("Invalid ID");
continue;
}
break;
case 3:
System.out.println("Enter the student ID: ");
int addID=input.nextInt();
System.out.print("Enter the student's dorm: ");
String dorm=input.next();
System.out.print("Enter the student's Covid Status");
String status=input.next();
Student s1=new Student(addID, dorm, status);
m.put(addID, s1);
String studentInfo=s1.toString();
System.out.println(studentInfo+" has been added to the database");
break;
case 4:
m.clear();
System.out.println("The database has been cleared");
break;
case 5:
System.out.println("Enter the file path name: ");
String fileIn=input.next();
File file=new File(fileIn);
if(file.exists()) {
try {
FileReader read=new FileReader(m, file);
}
catch(FileNotFoundException e1)
{
System.out.println("File is not in directory");
}
}
else {
System.out.println("Invalid file name");
}
break;
}
}
System.out.println("Thanks for checking out the Covid database! Please come again.");
}
}