-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
404 lines (390 loc) · 24.1 KB
/
Copy pathMain.java
File metadata and controls
404 lines (390 loc) · 24.1 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
import java.io.FileNotFoundException;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Scanner;
import java.time.format.DateTimeFormatter;
/**
* Main program for interacting with user and testing test cases
*
* CS1800 Spring 2022, Project 4
*
* @author Alex Lee
* @version 4/5/2022
*/
public class Main {
public static void main(String[] args) throws FileNotFoundException {
Tools tools = new Tools();
Scanner scan = new Scanner(System.in);
int initialResponse = 0;
Account newAccount = new Account();
System.out.println("What would you like to do?\n1. Create account\n2. Log in\n3. Exit");
initialResponse = tools.receiveValidInt(1, 3, scan);
switch ( initialResponse ) {
case 1:
boolean created;
do {
System.out.println("What do you want your username to be?");
String username = scan.nextLine();
newAccount = new Account(username, false);
// Ask user if they are a teacher or student
System.out.println("Are you a teacher or a student?\n1. Teacher\n2. Student");
String accountType = scan.nextLine();
if (accountType.equals("1")) {
newAccount = new Teacher(newAccount.getUsername(), false);
} else if (accountType.equals("2")) {
newAccount = new Student(newAccount.getUsername(), false);
}
created = newAccount.createAccount();
} while (!created);
System.out.println("Have a nice day!");
break;
case 2:
String accountType;
do {
System.out.println("What is your username?");
String username = scan.nextLine();
newAccount = new Account(username, false);
accountType = newAccount.logIn();
} while (!newAccount.isLogged());
if (accountType.equals("student")) {
newAccount = new Student(newAccount.getUsername(), true);
} else if (accountType.equals("teacher")) {
newAccount = new Teacher(newAccount.getUsername(), true);
}
break;
case 3:
System.out.println("Have a nice day!");
break;
default:
break;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
if ( newAccount.isLogged() ) {
if (newAccount instanceof Teacher) {
Teacher teacher = new Teacher(newAccount.getUsername(), true);
int option;
do {
System.out.println("What would you like to do?\n" +
"1. Create quiz\n2. Delete quiz\n3. Modify quiz\n4. View student submission\n" +
"5. Edit question pool\n6. Modify account" +
"\n7. Delete account\n8. Exit");
option = tools.receiveValidInt(1, 8, scan);
switch (option) {
case 1:
int randomQuiz;
System.out.println("Would you like to create a randomized quiz?\n1. Yes\n2. No");
randomQuiz = tools.receiveValidInt(1, 2, scan);
boolean flagError = false;
int numberQuestions = 0;
LocalDateTime deadline = null;
int duration = 0;
switch (randomQuiz) {
case 1:
System.out.println("How many questions would " +
"you like this quiz to have?");
numberQuestions = tools.receiveValidInt(0, scan);
do {
flagError = false;
System.out.println("When will be the deadline for this quiz" +
" (YYYY-MM-DD HH:MM)?");
String deadlineString = scan.nextLine();
try {
DateTimeFormatter deadlineFormat =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
deadline = LocalDateTime.parse(deadlineString, deadlineFormat);
} catch (Exception e) {
System.out.println("Please enter a valid response!");
flagError = true;
}
} while (flagError);
System.out.println("What will be the duration of this quiz (minutes)?");
duration = tools.receiveValidInt(0, scan);
teacher.createRandom(numberQuestions, deadline, duration, 4);
break;
case 2:
System.out.println("How many questions would you like this quiz to have?");
numberQuestions = tools.receiveValidInt(0, scan);
int[] questionIndex = new int[numberQuestions];
for (int i = 0; i < numberQuestions; i++) {
System.out.println("Which questions from" +
" the pool would you like to add?");
int index = tools.receiveValidInt(1, scan);
questionIndex[i] = index;
}
do {
flagError = false;
System.out.println("When will be the deadline for this quiz" +
" (YYYY-MM-DD HH:MM)?");
String deadlineString = scan.nextLine();
try {
DateTimeFormatter deadlineFormat =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
deadline = LocalDateTime.parse(deadlineString, deadlineFormat);
} catch (Exception e) {
System.out.println("Please enter valid responses!");
flagError = true;
}
} while (flagError);
System.out.println("What will be the duration" +
" of this quiz (minutes)?");
duration = tools.receiveValidInt(0, scan);
teacher.createCustom(numberQuestions, deadline, duration, questionIndex, new int[]{0});
break;
default:
break;
}
break;
case 2:
int quizID = 0;
System.out.println("Which quiz would you like to delete?");
quizID = tools.receiveValidInt(1, scan);
teacher.deleteQuiz(quizID);
break;
case 3:
quizID = 0;
Quiz quiz;
do {
System.out.println("Which quiz would you like to modify?");
quizID = tools.receiveValidInt(1, scan);
quiz = teacher.findQuiz(quizID);
if (quiz != null) {
int modifyQuizOption = 0;
System.out.printf("Quiz %d:\n", quizID);
System.out.println("What would you like to do?\n1. Modify questions\n" +
"2.Modify point values\n3. Modify deadline\n" +
"4. Modify duration");
modifyQuizOption = tools.receiveValidInt(1, 5, scan);
switch (modifyQuizOption) {
case 1:
int[] newQuestionIndexes = new int[quiz.getNumberQuestions()];
String questionIndexString = "";
for (int i = 0 ; i < quiz.getNumberQuestions() ; i++) {
questionIndexString += String.valueOf(quiz.getQuestionsIndex()[i]);
}
System.out.printf("Current question indexes: %s\n",
questionIndexString);
System.out.printf("Current question pool size: %d\n",
teacher.getQuestionPoolSize());
System.out.println("What will the new questions indexes be?");
for (int i = 0 ; i < quiz.getNumberQuestions() ; i++) {
System.out.printf("New question %d index:", i + 1);
int newIndex = tools.receiveValidInt(1,
teacher.getQuestionPoolSize(), scan);
newQuestionIndexes[i] = newIndex;
}
quiz.setQuestionsIndex(newQuestionIndexes);
System.out.println("Question indexes successfully updated!");
break;
case 2:
int[] questionPoints = quiz.getQuestionPoints();
for (int i = 0 ; i < questionPoints.length ; i++) {
System.out.printf("The current point value for question %d: %d\n",
i + 1, questionPoints[i]);
System.out.printf("What would you like the new point value for " +
"question %d to be?\n", i + 1);
int newPoint = tools.receiveValidInt(1, scan);
questionPoints[i] = newPoint;
}
quiz.setQuestionPoints(questionPoints);
System.out.println("Question points modified!");
break;
case 3:
System.out.printf("Current deadline: %s\n", quiz.getDeadline());
do {
flagError = false;
System.out.println("What would you like the new deadline to be?" +
"(YYYY-MM-DD HH:SS");
String newDeadline = scan.nextLine();
try {
DateTimeFormatter deadlineFormat =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
deadline = LocalDateTime.parse(newDeadline, deadlineFormat);
quiz.setDeadline(deadline);
System.out.println("Deadline modified");
} catch (Exception e) {
System.out.println("Please enter valid responses!");
flagError = true;
}
} while (flagError);
break;
case 4:
System.out.printf("Current duration: %d minutes\n", quiz.getDuration());
System.out.println("What would you like the new duration to be?");
duration = tools.receiveValidInt(0, scan);
quiz.setDuration(duration);
System.out.println("Duration modified!");
break;
default:
break;
}
} else {
System.out.println("This quiz doesn't exist!");
}
} while (quiz == null);
case 4:
String studentUsername;
System.out.println("Enter the username of the student:");
studentUsername = scan.nextLine();
System.out.println("Which quiz would you like to see?");
int wantedID = tools.receiveValidInt(1, scan);
String[] studentGradeAndTime = teacher.loadGrade(studentUsername, wantedID);
if (studentGradeAndTime != null) {
System.out.printf("The quiz grade for this student is: %s\nTaken at: %s\n",
studentGradeAndTime[0], studentGradeAndTime[1]);
}
break;
case 5:
System.out.println("What would you like to do?\n1. Add question\n2. Delete question\n" +
"3. Modify question");
int questionPoolMod = tools.receiveValidInt(1, 3, scan);
switch (questionPoolMod) {
case 1:
int questionTypeOption = 0;
System.out.println("What is the question type?\n1. Multiple choice\n" +
"2. Response\n3. True/False");
questionTypeOption = tools.receiveValidInt(1, 3, scan);
switch (questionTypeOption) {
case 1:
System.out.println("What is the question prompt?");
String prompt = scan.nextLine();
int multipleChoiceOptions;
System.out.println("How many options will this question have (min. 2)?");
multipleChoiceOptions = tools.receiveValidInt(2, scan);
String[] optionPrompts = new String[multipleChoiceOptions];
for ( int i = 0 ; i < multipleChoiceOptions ; i++) {
System.out.printf("What will be the option %d?\n", i + 1);
String optionPrompt = scan.nextLine();
optionPrompts[i] = optionPrompt;
}
System.out.printf("What is the question answer (1 - %d)?\n",
multipleChoiceOptions);
String answer = scan.nextLine();
teacher.addMultipleQuestion(prompt, answer, optionPrompts);
break;
case 2:
System.out.println("What is the question prompt?");
prompt = scan.nextLine();
System.out.println("What is the question answer?");
answer = scan.nextLine();
teacher.addResponseQuestion(prompt, answer);
break;
case 3:
System.out.println("What is the question prompt?");
prompt = scan.nextLine();
prompt = prompt + ": T or F";
System.out.println("What is the question answer (T/F)?");
answer = tools.receiveValidString(new String[]{"T", "F"}, scan);
teacher.addResponseQuestion(prompt, answer);
break;
default:
break;
}
break;
case 2:
System.out.println("Which question number would you like to delete?");
int questionNumber = tools.receiveValidInt(0, scan);
((Teacher) newAccount).deleteQuestion(questionNumber);
break;
case 3:
System.out.println("Which question number would you like to modify?");
questionNumber = tools.receiveValidInt(0, scan);
System.out.println("What would you like to do?\n" +
"1. Modify prompt\n2. Modify answer\n");
int modifyOption = tools.receiveValidInt(1, 2, scan);
switch (modifyOption) {
case 1:
System.out.println("What is the new prompt?");
String newPrompt = scan.nextLine();
((Teacher) newAccount).modifyQuestionPrompt(questionNumber, newPrompt);
break;
case 2:
System.out.println("What is the new answer?");
String newAnswer = scan.nextLine();
((Teacher) newAccount).modifyQuestionAnswer(questionNumber, newAnswer);
break;
default:
break;
}
break;
default:
break;
}
break;
case 6:
boolean modified;
do {
System.out.println("Enter a new username");
String newUsername = scan.nextLine();
modified = teacher.modifyAccount(newUsername);
} while (!modified);
break;
case 7:
newAccount.deleteAccount();
System.out.println("Have a nice day!");
break;
case 8:
System.out.println("Have a nice day!");
break;
default:
break;
}
} while(option != 8);
////////////////////////////////////////////////////////////////////////////////////////////////////
} else if (newAccount instanceof Student) {
Student student = new Student(newAccount.getUsername(), true);
int option = 0;
boolean flagError = false;
do {
System.out.println("What would you like to do?\n" +
"1. Take quiz\n2. View quiz submissions\n3. Modify account\n4. Delete account\n" +
"5. Exit");
option = tools.receiveValidInt(1, 5, scan);
switch(option) {
case 1:
int quizID = 0;
Quiz quiz;
System.out.println("Which quiz would you like to take?");
quizID = tools.receiveValidInt(1, scan);
quiz = student.loadQuiz(quizID);
if ( quiz != null) {
String[] responses = student.takeQuiz(quiz);
float grade = quiz.gradeQuiz(responses);
LocalDateTime timestamp = LocalDateTime.now();
student.recordGrade(grade, quizID, timestamp);
}
break;
case 2:
quizID = 0;
System.out.println("Which quiz grade would you like to view?");
quizID = tools.receiveValidInt(1, scan);
String quizGrade = student.loadGrade(quizID);
if ( quizGrade == null ) {
System.out.println("You have not taken this quiz yet!");
} else {
System.out.printf("Grade: %s\n", quizGrade);
}
break;
case 3:
boolean modified;
do {
System.out.println("Enter the new username");
String newUsername = scan.nextLine();
modified = newAccount.modifyAccount(newUsername);
} while (!modified);
break;
case 4:
newAccount.deleteAccount();
System.out.println("Have a nice day!");
option = 5;
break;
case 5:
System.out.println("Have a nice day!");
break;
default:
break;
}
} while ( option != 5);
}
}
}
}