public bool studentExists(int id) { /* * pre cond: int id * post cond: true - if student id is found in stack * false - otherwise * * checks if a student id was already used */ Student student; Stack newStack = new Stack(this.repo.getStackCapacity()); bool ok = false; while (!ok && this.repo.getStackSize() > -1) { student = this.repo.getStudent(); if (student.getId() == id) ok = true; newStack.push(student); } while (newStack.getStackSize() > -1) this.repo.addStudent(newStack.pop()); if (ok) return true; else return false; }
public String getAllStudents() { /* * pre cond: - * post cond: a string with all the students * or a message if no students have been added * */ String studentList = ""; Student student; if (repo.getStackSize() < 0) return "No students!"; Stack newStack = new Stack(this.repo.getStackCapacity()); while (this.repo.getStackSize() > -1) { student = this.repo.getStudent(); studentList += student.toString() + "\n"; newStack.push(student); } while (newStack.getStackSize() > -1) this.repo.addStudent(newStack.pop()); return studentList; }