-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLearningSystem.java
More file actions
81 lines (76 loc) · 3 KB
/
LearningSystem.java
File metadata and controls
81 lines (76 loc) · 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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class LearningSystem {
public static ArrayList<Instructor> instructors = new ArrayList<Instructor>();
public static ArrayList<Student> students = new ArrayList<Student>();
public static ArrayList<Assignment> assignments = new ArrayList<Assignment>();
public static User activeUser;
public LearningSystem(){
readInstructors();
readStudents();
readAssignments();
}
public static void readInstructors(){
try {
File myObj = new File("static/Instructors.csv");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
String[] arrOfData = data.split(",", -1);
int id = Integer.parseInt(arrOfData[0]);
String name = arrOfData[1];
String email = arrOfData[2];
String hashPass = arrOfData[3];
Instructor i1 = new Instructor(id, name, email, hashPass);
instructors.add(i1);
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
public static void readStudents() {
try {
File myObj = new File("static/Students.csv");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
String[] arrOfData = data.split(",", -1);
int id = Integer.parseInt(arrOfData[0]);
String name = arrOfData[1];
String email = arrOfData[2];
String hashPass = arrOfData[3];
int presents = Integer.parseInt(arrOfData[4]);
int absents = Integer.parseInt(arrOfData[5]);
Student s1 = new Student(id, name, email, hashPass, presents, absents);
students.add(s1);
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
public static void readAssignments() {
try {
File myObj = new File("static/Assignments.csv");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
String[] arrOfData = data.split(",", -1);
int sID = Integer.parseInt(arrOfData[0]);
String comment = arrOfData[1];
String path = arrOfData[2];
Assignment a1 = new Assignment(sID, comment, path);
assignments.add(a1);
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}