package uiquiz;

import javax.swing.JOptionPane;

public class School {

    //2.1.1
    private String school;
    private String area;
    private Student student[] = new Student[2];

    //2.1.2
    public School(String s, String a, Student[] studentArray) {
        school = s;
        area = a;                               //OR done in a bad way:
        student = studentArray;
    }

    //2.1.3
    public String getSchool() {
        return school;
    }

    public String getArea() {
        return area;
    }

    //2.1.4
    public String toString() {
        String output = "";                                     //OR done in a bad way:

        output = school + " (" + area + ")\n";                  //   return school + " (" + area + ")\n"
        //           + student[0].toString + "\n"
        for (int i = 0; i < 2; i++) {                           //           + student[1].toString + "\n";
            if (student[i] != null) {
                output = output + student[i].toString() + "\n";     // inserting the if statement here we will only add
            }
        }                                                       // a student's data to output when it is not empty.

        return output;
    }

    //2.1.5
    public void insertStudent_ID_IQ(Student learner) {

        for (int i = 0; i < 2; i++) {

            if (student[i] == null) {
                student[i] = learner;
                break;
            }

        }
    }

    //2.1.6
    public int maxIQ() {
        int highestIQ = 0;
        for (int i = 0; i < 2; i++) {
            if (student[i].getStudentIQ() > highestIQ) {
                highestIQ = student[i].getStudentIQ();
            }
        }
        return highestIQ;
    }

    //2.1.7   
    public int countAboveAvg() {
        int count = 0;
        for (int i = 0; i < 2; i++) {
            if (student[i].isOnPar() == true) {     //OR better: if ( student[i].isOnPar() ) 
                count++;                              // Whenever we want to say "== true" we can just leave it out.
            }
        }
        return count;
    }

}
