public static void main(String[] args) {
    Course course = new Course("Introduction to java", 10);
    Student student1 = new Student("0001", "Connor", "Cheng", true);
    Student student2 = new Student("0002", "Judy", "Cheng", false);

    Class theClass = new Class(course);
    theClass.addStudent(student1);
    theClass.addStudent(student2);

    theClass.dropStudent(student1);
    System.out.println(theClass.toString());
  }
Example #2
0
 public static ScoreMenu[] loadFile() {
   MainWindow.initDataFile(SCORE_MENU_FILE);
   DataInputStream input;
   Course course;
   Class tempClass;
   Student student;
   int[] testTime;
   long[] id;
   float[] score;
   ScoreMenu[] scoreMenu = new ScoreMenu[20];
   int count = 0;
   try {
     input = new DataInputStream(new FileInputStream(SCORE_MENU_FILE));
     while (input.available() > 0) {
       if (count >= scoreMenu.length) {
         ScoreMenu[] temp = new ScoreMenu[scoreMenu.length * 2];
         for (int i = 0; i < scoreMenu.length; i++) temp[i] = scoreMenu[i];
         scoreMenu = temp;
       }
       tempClass = new Class();
       tempClass.setGrade(input.readInt());
       tempClass.setMajor(input.readUTF());
       tempClass.setClassNumber(input.readInt());
       tempClass.setStudentNumber(0);
       int num = input.readInt();
       for (int i = 0; i < num; i++) {
         student = new Student();
         student.setId(input.readLong());
         student.setName(input.readUTF());
         tempClass.addStudent(student);
       }
       course = new Course();
       course.setId(input.readUTF());
       course.setName(input.readUTF());
       course.setCredit(input.readFloat());
       course.setPeriod(input.readInt());
       testTime = new int[5];
       for (int i = 0; i < 5; i++) testTime[i] = input.readInt();
       num = input.readInt();
       id = new long[num];
       score = new float[num];
       for (int i = 0; i < num; i++) id[i] = input.readLong();
       for (int i = 0; i < num; i++) score[i] = input.readFloat();
       scoreMenu[count] = new ScoreMenu(tempClass, course, testTime, num, id, score);
       count++;
     }
     input.close();
     return scoreMenu;
   } catch (Exception e) {
     return null;
   }
 }
Example #3
0
 public static ScoreMenu queryFromFile(Class classes, Course courses) {
   MainWindow.initDataFile(SCORE_MENU_FILE);
   DataInputStream input;
   Class tempClass = new Class();
   Student student;
   Course course = new Course();
   int[] testTime = new int[5];
   int numberOfAttendTestStudent;
   long idOfStudents[];
   float scoreOfTest[];
   try {
     input = new DataInputStream(new FileInputStream(SCORE_MENU_FILE));
     while (input.available() > 0) {
       tempClass.setGrade(input.readInt());
       tempClass.setMajor(input.readUTF());
       tempClass.setClassNumber(input.readInt());
       int studentNumber = input.readInt();
       tempClass.setStudentNumber(0);
       for (int i = 0; i < studentNumber; i++) {
         student = new Student();
         student.setId(input.readLong());
         student.setName(input.readUTF());
         tempClass.addStudent(student);
       }
       course.setId(input.readUTF());
       course.setName(input.readUTF());
       course.setCredit(input.readFloat());
       course.setPeriod(input.readInt());
       for (int i = 0; i < 5; i++) testTime[i] = input.readInt();
       numberOfAttendTestStudent = input.readInt();
       idOfStudents = new long[numberOfAttendTestStudent];
       scoreOfTest = new float[numberOfAttendTestStudent];
       for (int i = 0; i < numberOfAttendTestStudent; i++) idOfStudents[i] = input.readLong();
       for (int i = 0; i < numberOfAttendTestStudent; i++) scoreOfTest[i] = input.readFloat();
       if ((classes.equals(tempClass)) && (courses.equals(course))) {
         input.close();
         return new ScoreMenu(
             tempClass, course, testTime, numberOfAttendTestStudent, idOfStudents, scoreOfTest);
       }
     }
     input.close();
     return null;
   } catch (Exception e) {
     return null;
   }
 }