Beispiel #1
0
        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;
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public String deleteStudentsUntilGrade(int grade)
        {
            /*
             * pre cond: int grade (the limit grade)
             * post cond: specific string
             *
             * deletes all students until 'grade' is found
             */

            Stack newStack = new Stack(this.repo.getStackCapacity());
            Student student;
            while (this.repo.getStackSize() > -1)
            {
                student = this.repo.getStudent();
                if (student.getGrade() == 10)
                {
                    this.repo.addStudent(student);
                    return "Students deleted successfully!";
                }
                newStack.push(student);
            }
            return "No students with the grade 10 found; all students have been deleted!";
        }
Beispiel #4
0
        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;
        }