import java.util.ArrayList; public class ClassRosterNStudentRunner { public ClassRosterNStudentRunner() { ArrayList students = new ArrayList(); Student vinnie = new Student("vinnie", 16) ; Student amelia = new Student("Amelia", 15 ); Student daniyal = new Student("Daniyal ", 16 ); Student rany = new Student("rany ", 17 ); Student haku = new Student("haku ", 17 ); Student ryan = new Student("ryan ", 666 ); //add 3 students to the arraylist students.add(vinnie ); students.add(amelia); students.add(daniyal ); students.add(rany ); students.add(haku ); students.add(ryan ); ClassRoster cr = new ClassRoster(); int correct = 0 ; int wrong = 0 ; p("----------Begin testing ClassRoster ----------"); boolean nullAtDefault = false; try{ cr.addStudent(vinnie); } catch(NullPointerException e){ nullAtDefault = true; } if(nullAtDefault) { wrong++ ; p("Error. Probably never initialized myStudents ArrayList @ default constructor") ; cr.addStudent(vinnie); // let runtime error actually happen this time } else{ correct++; } int period = 2 ; cr = new ClassRoster( 2 ); boolean nullAtNonDefault = false ; try{ cr.addStudent(vinnie); } catch(NullPointerException e){ nullAtNonDefault = true; } if(nullAtNonDefault) { wrong++ ; p("Error. Probably never initialized myStudents ArrayList @ NON default constructor") ; cr.addStudent(vinnie); // let runtime error actually happen this time } else{ correct++; } //done testing constructors for non initialized variables // if(cr.contains(vinnie) == false ) { wrong++ ; p("contains() error"); } else{ correct++; } if(cr.contains(new Student("Tim", 42)) ) { wrong++ ; p("contains(Student st) error "); } else{ correct++; } //cr is still empty if(cr.contains(amelia.getSSN()) == true ) { wrong++ ; p("contains(int ssnId) error"); } else{ correct++; } //now add the studetns to the classRoster for(Student st: students) cr.addStudent(st); //should work this time if(cr.contains(amelia.getSSN()) == false ) { wrong++ ; p("contains(int ssnId) error"); } else{ correct++; } if(cr.equals(new ClassRoster())) { wrong++ ; p("equals()) error"); } else{ correct++; } //test mutators //new student ArrayList studentsNow = cr.getStudents(); int num = studentsNow.size(); Student jorge = new Student("jorge"); cr.addStudent(jorge); cr.addStudent(new Student("dimitry", 16)); if( num + 2 == cr.getStudents().size()) correct++; else{ p("addStudent() and/or addStudent(Student st) not working") ; wrong++; } studentsNow = cr.getStudents(); num = studentsNow.size(); cr.removeStudent(amelia.getSSN()); if( num - 1 == cr.getStudents().size()) correct++; else{ p("removeStudent(int ssnId) error ") ; wrong++; } studentsNow = cr.getStudents(); num = studentsNow.size(); cr.removeStudent(haku) ; if( num - 1 == cr.getStudents().size()) correct++; else{ p("removeStudent(Student st) error ") ; wrong++; } studentsNow = cr.getStudents(); num = studentsNow.size(); cr.removeStudent(rany.getName()) ; if( num - 1 == cr.getStudents().size()) correct++; else{ p("removeStudent(String name) error ") ; wrong++; } p("----------End testing ClassRoster ----------"); p("*************** Test results ******************************") ; p("***********************************************************") ; p("***********************************************************") ; p("\t\t No. correct " + correct); p("\t\t No. wrong : " + wrong); p("***********************************************************") ; p("***********************************************************") ; p("***********************************************************") ; } void p(int i){ System.out.println(i); } void p(String i){ System.out.println(i); } void p(double i){ System.out.println(i); } void p(boolean i){ System.out.println(i); }