dimanche 7 avril 2019

What is wrong with my code? I'm not getting the right expected output? Can someone explain please

I'm trying to make an addStudent method where it takes a student classed student list and add it to a course list inside my course class. The method I'm making addStudent doesn't seem to be outputting the actual output I'm expecting it to be. Can someone explain why my logic doesn't work here?

Logic: I'm trying to check If the student is in good standing >>> if the class size is big enough >> add student

Code :

    /**
     * Adding student to an course list and checking if the student passes standing AND size limit 
     * @param stn
     * @return 
     */
    public String addStudent(Student stn) 
    {
        for(int s = 0; s < studentList.size(); s++)
            {
              if((studentList.get(s).inGoodStanding()) == true)   
              {
                  if (studentList.size() <= 5 )
                  {
                      studentList.add(stn); 
                  }      
                  else
                  {
                      return ("Student was not added because the course is full");
                  }
              }
              else 
              {
                  return ("The Student is not in good standing and cannot join the course.");
              }
            }
       return ("some error happened ");
    }

output: some error happened

Try: I have tried to put a break after studentList.add(stn);

Aucun commentaire:

Enregistrer un commentaire