public void validateStudent(Student s) { if (this.nameIsEmpty(s.getName())) throw new StudentException("Name cannot be empty!\n"); if (this.studentExists(s.getId())) throw new StudentException("Student id already exists!\n"); }
public String addStudent(String name, int id, int grade) { /* * Asks validator if the student id is already used * returns string if so * if not, repository is called and student object is added * * pre cond: string name, int id, int grade (of the student) * post cond: string with status message */ /* if (this.val.nameIsEmpty(name)) throw new StudentException("Name cannot be empty!"); if (this.val.studentExists(id)) return "Student id already exists!"; Student s = new Student(name, id, grade); this.repo.addStudent(s); return "Student added successfully!"; */ try { Student s = new Student(name, id, grade); this.val.validateStudent(s); this.repo.addStudent(s); return "Student added successfully!"; } catch (StudentException ex) { return ex.getMessage(); } }
public void addStudent(Student s) { /* * pre cond: s of type Student * post cond: - * * Adds on top of the stack a student object */ stack.push(s); }
public void push(Student s) { /* * pre cond: s of type Student * post cond: - * * adds object on top of stack; if maximum capacity is reached, * it doubles it */ size++; if (size == capacity) increaseCapacity(); students[size] = s; }