コード例 #1
0
ファイル: Validator.cs プロジェクト: csergiu/Labs
        private 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;
        }
コード例 #2
0
ファイル: StudentController.cs プロジェクト: csergiu/Labs
 public String deleteStudentsUntilGrade(int grade)
 {
     /*
     * pre cond: int grade (the limit grade)
     * post cond: specific string
     *
     * deletes all students until 'grade' is found
     */
     try
     {
         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!";
     }
     catch (StudentException ex)
     {
         return ex.getMessage();
     }
 }
コード例 #3
0
ファイル: StudentController.cs プロジェクト: csergiu/Labs
        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;
        }
コード例 #4
0
ファイル: StudentRepository.cs プロジェクト: csergiu/Labs
 public StudentRepository(int capacity)
 {
     this.capacity = capacity;
     this.stack = new Stack(capacity);
 }