public ArrayList<Course> initialCourseList() { ArrayList<Course> courseList = new ArrayList<Course>(); try { br = new BufferedReader(new FileReader("data/course.txt")); while ((line = br.readLine()) != null) { String[] split = line.split(" "); Course newCourse = new Course(); newCourse.setCourseId(split[0]); newCourse.setCourseName(split[1]); newCourse.setCompulsory(split[2].equals("true") ? true : false); newCourse.setPeriod(Integer.parseInt(split[3])); newCourse.setScore(Integer.parseInt(split[4])); User newTeacher = new Teacher(); newTeacher.setId(split[5]); newTeacher.setType("teacher"); newTeacher.setPassword(null); newCourse.setTeacherUser(newTeacher); newCourse.setTime(split[6]); newCourse.setClassroom(split[7]); int i = 8; ArrayList<User> list = new ArrayList<User>(); while (i < split.length) { Student newStudent = new Student(); newStudent.setId(split[i]); newStudent.setType("student"); newStudent.setPassword(null); list.add(newStudent); i++; } newCourse.setAssistStudentList(list); courseList.add(newCourse); } } catch (IOException ex) { ex.printStackTrace(); } return courseList; }
public ArrayList<User> initialStudentList() { ArrayList<User> studentList = new ArrayList<User>(); try { br = new BufferedReader(new FileReader("data/student.txt")); while ((line = br.readLine()) != null) { String[] split = line.split(" "); Student newStudent = new Student(); newStudent.setId(split[0]); newStudent.setName(split[1]); newStudent.setPassword(split[2]); newStudent.setType("student"); studentList.add(newStudent); } } catch (IOException ex) { ex.printStackTrace(); } return studentList; }