-
Notifications
You must be signed in to change notification settings - Fork 0
/
Teacher.java
392 lines (356 loc) · 17.7 KB
/
Teacher.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
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
/*This class is the main class which will handle all the functionalities of the Teacher.*/
import java.io.*;
import java.util.*;
class Teacher {
String name, subject="OOP";
Scanner src = new Scanner(System.in);
// File Teacher_file_pointer= new File();
Teacher(String name) { // Constructor to get the credentials of current logged in Teacher.
this.name = name;
}
// Welcome function for the LoggedIN Teacher which will display his/her name,
// subject he/she teaches and offers a choice of Actions.
final void welcome() {
int choice;
boolean c = true;
System.out.println("####################################################################################");
System.out.println(" Welcome " + name + "!");
System.out.println("####################################################################################");
//Main menu for the Teacher which logs in the system.
while (c) {
System.out.println("\n**************************************************************************************");
System.out.println("Enter your choice:-");
System.out.println("1 to Add Quiz question/s for your Subject.\n2 to see Progress of the Class.\n-1 to Logout.");
System.out.println("**************************************************************************************");
while(true){
try{
choice = src.nextInt();
break;
}catch(InputMismatchException e){
System.out.println("Invalid Input. Please Enter your choice again.");
src.nextLine();
}
}
switch (choice) {
case 1:
// Functions to handle the Question adding functionality
System.out.println("\n------------------------------------------------------------------------");
System.out.println("------------------------------------------------------------------------");
System.out.println("Enter the name of Subject for which you want to add the Quiz.");
System.out.println("OOP\nDE\nDSA");
System.out.println("------------------------------------------------------------------------");
System.out.println("------------------------------------------------------------------------");
while(true){
try{
subject = src.nextLine();
subject = src.nextLine();
break;
}catch(InputMismatchException e){
System.out.println("Invalid Input. Please Enter your choice again.");
src.nextLine();
}
}
//Will add a loop to display all the choice of Subjects that he/she teaches
//{}
subject = subject.toUpperCase();
boolean flag=true;
while(flag){
int choice2 = choose_among_the_chapters_of_the_subject(subject);
switch (choice2) {
case 1:
q_and_a((subject + "_CHAPTER01.txt"));
flag=false;
break;
case 2:
q_and_a((subject + "_CHAPTER02.txt"));
flag=false;
break;
case 3:
q_and_a((subject + "_CHAPTER03.txt"));
flag=false;
break;
default:
System.out.println("You entered a wrong choice for Chapter.");
}}
break;
case 2:
int c1=-1;
boolean flag2=true;
while(flag2){
System.out.println("\n------------------------------------------------------------------------");
System.out.println("------------------------------------------------------------------------");
System.out.println("You chose to fetch the Progress Report.\nEnter your choice.\n1.Progress report of whole class combined.\n2.Progress report of an individual student");
System.out.println("------------------------------------------------------------------------");
System.out.println("------------------------------------------------------------------------");
while(true){
try{
c1 = src.nextInt();
break;
}catch(InputMismatchException e){
System.out.println("Invalid Input. Please Enter your choice again.");
src.nextLine();
}
}
if(flag2){
switch(c1){
case 1:
File class_ref = new File("C://Manish//The_Test_Taker//All_Text_files//Student_Record//Class_data.txt");
//Function to display the progress of the whole class.
flag2=getReport(class_ref);
break;
case 2:
String roll_no;
System.out.println("Enter the roll no of the student whose Progress Report yu want to generate:-");
while(true){
try{
roll_no = src.nextLine();
roll_no = src.nextLine();
break;
}catch(InputMismatchException e){
System.out.println("Invalid Input. Please Enter your choice again.");
src.nextLine();
}
}
//Function to display the progress of an individual student.
flag2=getReport(roll_no);
break;
default:
System.out.println("Enter a valid Argument.");
}
}
}
break;
case -1:
//c = false;
System.out.println("Logged out Successfully.");
return;
//break;
default:
System.out.println("Please Enter a valid choice.");
}
}
return;
}
private int choose_among_the_chapters_of_the_subject(String subject){
int chapter=-1;
File subject_index= new File("C://Manish//The_Test_Taker//All_Text_files//Quizes//SEM_3//"+subject+"//Subject_index.txt");
Scanner chapter_read= null;
try{
chapter_read= new Scanner(subject_index);
}catch(FileNotFoundException e){
System.out.println("Try Again");
//chapter=choose_among_the_chapters_of_the_subject(subject,semester);
return chapter;
}
//This will display the list of the chapters available in a subject by traversing the subject index of each subject
String line_will_be_of_use_sometime=chapter_read.nextLine();
while(!(line_will_be_of_use_sometime.equals("List of chapters:-")))
{
line_will_be_of_use_sometime=chapter_read.nextLine();
}
System.out.println("************************************************");
System.out.println(line_will_be_of_use_sometime);
line_will_be_of_use_sometime=chapter_read.nextLine();
int no_of_chapters=0;
while(line_will_be_of_use_sometime.charAt(0)!='#'){
System.out.println(line_will_be_of_use_sometime);
line_will_be_of_use_sometime=chapter_read.nextLine();
no_of_chapters++;//To get the count of the chapters available
}
System.out.println("************************************************");
//Asking user for his/her choice of Chapter.
int chap;
System.out.println("Enter the number of the Chapter from above whose Quiz you want to take.");
//String chap1= input.next();
//chap=Integer.parseInt(chap1);
while(true){
try{
chap = src.nextInt();
break;
}catch(InputMismatchException e){
System.out.println("Invalid Input. Please Enter your choice again.");
src.nextLine();
}
}
if(chap>no_of_chapters){//If the user enters some wrong chapter_no then we'll call this function again and ask his/her to choose.
System.out.println("You entered a wrong choice of Chapter.");
chapter=choose_among_the_chapters_of_the_subject(subject);
}else{
chapter=chap;
}
chapter_read.close();
return chapter;
}
//This function asks the Teacher to entera aquestion one by one followed by it's answer.
final void q_and_a(String file_name) {
int c = 1;
// File object for the specific chapter.
File q_and_a = new File("C://Manish//The_Test_Taker//All_Text_files//Quizes//SEM_3//"+subject+"//" + file_name);
if (q_and_a.exists()) {
System.out.println("\nFile opened successfully.");
} else {
System.out.println("not found");
return;
}
Boolean check = false;
String question;
String[] answer = new String[5];
Scanner append_data=null;
int i=0;
while (c == 1) {
try {
append_data = new Scanner(q_and_a);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
System.out.println("\n--------------------------------------------------------------------------------------");
System.out.println("Enter your Question:-");
System.out.println("--------------------------------------------------------------------------------------");
question = src.nextLine();
question = src.nextLine();
//First we check if the question already exist in the questionarre.
while (append_data.hasNextLine()) {
if (question.equals(append_data.nextLine())) {
System.out.println("\n\nThis question already exists in the Questionarre.");
check = true;//Flag to store that the input question already exist in the file.
}
}
//Appending the data into the file only if the question doesnot exist in the file previously.
if (check == false) {
while(i<4){
System.out.println("Enter Option("+(i+1)+")");
answer[i] = src.nextLine();
i++;
}
System.out.println("Enter the correct option:-(A/B/C/D)");
while(true){
answer[4]=src.nextLine().toUpperCase();
if(answer[4].equals("A")||answer[4].equals("B")||answer[4].equals("C")||answer[4].equals("D")){
break;
}else{
System.out.println("Enter a valid Option from A/B/C/D");
}
}
append_data.close();i=0;
FileWriter writer;
try {
writer = new FileWriter(q_and_a, true);
writer.write("\r\n");
writer.write(question);
writer.write("\r\n(A)"+answer[0]+
"\r\n(B)"+answer[1]+
"\r\n(c)"+answer[2]+
"\r\n(D)"+answer[3]);
writer.write("\r\n");
writer.write("Correct option:-"+answer[4]);
writer.write("\r\n");
writer.write("*****************************************************************");
writer.close();
System.out.println("\nQuestion/s added successfully.");
} catch (IOException e) {
e.printStackTrace();
System.out.println("Couldnot complete the operation.\nPlease try again.");
}}
System.out.println("--------------------------------------------------------------------------------------");
System.out.println("Do you want to add another Question?");
System.out.println("1. YES\n0. NO");
System.out.println("--------------------------------------------------------------------------------------");
try{
c=src.nextInt();
}catch(Exception e){
System.out.println("Invalid type of Argument.");
q_and_a(file_name);
}
}
}
//This funation will print the progress report for the whole class.
//It will traverse the master file having required data of all the students and display them in a proper manner.
boolean getReport(File f1){
Scanner reader = null;
try{
reader=new Scanner(f1);
}catch(FileNotFoundException e){
System.out.println("Something's not right. Try again.");
return true;
}
float class_total=0;
int counter=0;
System.out.println("###################################################################################################");
System.out.println(" The cummulative progress of the class is display below ");
System.out.println("###################################################################################################");
System.out.println(" Name Roll No Total Quizes Total Marks Percentage ");
int i=0;
while(i<5){
reader.nextLine();
i++;
}
while(reader.hasNextLine()){
String STUDENT_name=reader.nextLine();
String rollo = reader.nextLine();
String useless= reader.nextLine();
File student_file = new File("C://Manish//The_Test_Taker//All_Text_Files//Student_record//"+rollo+".txt");
Scanner input= null;
try{
input=new Scanner(student_file);
}catch(IOException e){
System.out.println("Error");
continue;
}
String total_marks=null,avg=null;
String used= input.nextLine();
while(!(used.contains("Total marks"))){
if(input.hasNextLine()){
used=input.nextLine();
}else{
System.out.println("error");
}
}
total_marks= used.substring(13);
used=input.nextLine();
avg=used.substring(9);
input.close();
class_total+=Float.parseFloat(total_marks);
counter++;
System.out.println(STUDENT_name+"\t\t"+rollo+"\t\t10"+"\t\t"+total_marks+"\t\t"+avg);
}
//Calculate the standard deviation of the data of the class
//Calculate the coefficient of variation
System.out.println(" Class Total:-"+class_total);
System.out.println("##################################################################################");
reader.close();
return false;
}
//This function will generate the report card for an Individual student.
boolean getReport(String rollno){
File student = new File("C://Manish//The_Test_Taker//All_Text_files//Student_Record//"+rollno+".txt");
Scanner read=null;
try{
read= new Scanner(student);
}catch(FileNotFoundException e){
System.out.println("Something's not right. Please try again");
return true;
}
int i=0;
while(i<3){
read.nextLine();
i++;
}
String student_name= read.nextLine();
System.out.println("#################################################################################");
System.out.println(" Progress Report of-"+student_name.substring(6));
System.out.println("#################################################################################");
while(read.hasNextLine()){
String line=read.nextLine();
System.out.println(line);
}
System.out.println("\n\n\n");
read.close();
return false;
}
}
class Testing{
public static void main(String args[]){
Teacher t1= new Teacher("Manish");
t1.welcome();
}
}