-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.java
122 lines (118 loc) · 4.87 KB
/
User.java
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
111
112
113
114
115
116
117
118
119
120
121
122
import java.util.Scanner;
/**
* The `User` class represents a user of various types and has different
* commands for each type of user.
*/
public class User {
private String userType;
private Object userObject;
/**
* Constructor for objects of class User
*
* @param _userType type of the user as a String
* @param _userObject type of the user as an Object
*/
public User(String _userType, Object _userObject) {
this.userType = _userType;
this.userObject = _userObject;
}
/**
* Runs the sub-interpreter.
*/
public void run() {
Scanner in = new Scanner(System.in);
boolean run = true;
if (userType.equals("Student")) {
Student stud = (Student) userObject;
while (run) {
System.out.println("Commands: (G)et transcript, (E)xit");
String command = in.nextLine().toUpperCase();
switch (command) {
case "G":
stud.getTranscript();
break;
case "E":
run = false;
break;
default:
System.out.println("Invalid command.");
}
}
} else if (userType.equals("Faculty")) {
Faculty facu = (Faculty) userObject;
while (run) {
System.out.println("Commands: (A)dd grade, (G)et transcript, (E)xit");
String command = in.nextLine().toUpperCase();
String id;
switch (command) {
case "A":
System.out.println("What is the Student's ID?");
id = in.nextLine();
if (Interpreter.returnStudent(id) == null) {
System.out.println("Student doesn't exist");
break;
}
System.out.println("What is the module's name?");
String code = in.nextLine().toUpperCase();
if (Interpreter.returnModule(code) == null) {
System.out.println("Module doesn't exist");
break;
}
Module mod = Interpreter.returnModule(code);
// Module m = new Module(code, code);
// m.setEnrolledStudents(CSVReader.readClassRole(code + ".csv"));
System.out.println("What is the result?");
String grade = in.nextLine();
facu.addGradeToModule(new Student(id), mod, Double.parseDouble(grade));
break;
case "G":
System.out.println("Enter Student ID?");
id = in.nextLine();
if (Interpreter.returnStudent(id) == null) {
System.out.println("Student doesn't exist");
break;
}
Student student = Interpreter.returnStudent(id);
facu.getStudentTranscript(student);
break;
case "E":
run = false;
break;
default:
System.out.println("Invalid command.");
}
}
} else if (userType.equals("Department")) {
Department depa = (Department) userObject;
System.out.printf("[Faculty of %s]\n", (depa.getName()).toUpperCase());
while (run) {
System.out.println("Commands: (W)rite Message, (H)old Exam Board, (E)xit");
String command = in.nextLine().toUpperCase();
switch (command) {
case "W":
System.out.println("What is the student's ID?");
String id = in.nextLine();
if (Interpreter.returnStudent(id) == null) {
System.out.println("Student doesn't exist");
break;
}
System.out.println("What is the message?");
String message = in.nextLine();
depa.writeMessageToStudent(id, message);
break;
case "H":
depa.holdExamBoard();
break;
case "E":
run = false;
break;
default:
System.out.println("Invalid command.");
}
}
}
// DO NOT CLOSE SCANNER HERE.
// JAVA ONLY ALLOWS ONE FOR PROGRAM.
// CLOSING HERE CLOSES ALL.
}
}