@Test
  public void classRosterTestFindStudent() throws Exception {
    roster.loadRoster();
    Student thisStudent = roster.viewStudentInfo("studentId");

    assertEquals("firstName", thisStudent.getFirstName());
  }
  @Test
  public void classRosterTestAddStudent() {
    Student newStudent = new Student("firstName", "lastName", "studentId", "cohort");

    roster.addStudent(newStudent.getStudentId(), newStudent);

    assertEquals(1, roster.countStudents());
  }
  @Test
  public void classRosterTestSaveAndLoadRoster() throws Exception {
    Student newStudent = new Student("firstName", "lastName", "studentId", "cohort");

    roster.addStudent(newStudent.getStudentId(), newStudent);
    roster.saveRoster();
    roster.removeStudent("studentId");
    roster.loadRoster();

    assertEquals(1, roster.countStudents());
  }
示例#4
0
  public void loadRoster() throws RosterAccessException {
    try {
      Scanner fin = new Scanner(new FileReader(ROSTER_FILE));
      String[] stringTokens;

      while (fin.hasNextLine()) {
        stringTokens = fin.nextLine().split(DELIMITER);

        Student student =
            new Student(stringTokens[1], stringTokens[2], stringTokens[0], stringTokens[3]);
        students.put(student.getStudentId(), student);
      }

      fin.close();
    } catch (FileNotFoundException e) {
      throw new RosterAccessException();
    }
  }
示例#5
0
  public void saveRoster() throws RosterAccessException {
    try {
      PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(ROSTER_FILE)));

      for (Student eachStudent : students.values()) {
        out.println(
            eachStudent.getStudentId()
                + DELIMITER
                + eachStudent.getFirstName()
                + DELIMITER
                + eachStudent.getLastName()
                + DELIMITER
                + eachStudent.getCohort());

        out.flush();
      }

      out.close();
    } catch (IOException e) {
      throw new RosterAccessException();
    }
  }