title: JAVA Inheritance student, undergrad and gradstudent code
body: <p>For a class project I was asked to create three codes. 
  Student Class</p>
  
  <ol>
  <li><p>First, the student class containing three Parameters. </p>
  
  <ul>
  <li>Name(String) </li>
  <li>TestScores( int array),</li>
  <li>Grade(String). </li>
  </ul></li>
  <li><p>An empty Constructor. sets the Name and Grade to empty Strings. The TestScores Array will be initialised with three zeros. </p></li>
  <li><p>Another Constructor(String n, int[] tests, String g)- This will set the <code>name</code>, <code>testScores</code>, and <code>grade</code>. </p></li>
  <li><p>Three methods:</p>
  
  <ul>
  <li><code>getName()</code> to return the <code>name</code></li>
  <li><code>getGrade()</code> to return the <code>grade</code></li>
  <li><code>setGrade()</code> to set <code>grade</code></li>
  <li><code>getTestAverage()</code> to return the average of the test scores. </li>
  </ul></li>
  <li><p><em>This is where I am having difficulty</em> The method <code>computeGrade()</code>, which, if the average is greater than or equal to 65, the grade is a "Pass". Otherwise it is a "Fail". </p></li>
  </ol>
  
  <p>The second class is called <code>UnderGrad</code>. This class is a subclass of Student. </p>
  
  <ol>
  <li><p>We had to create an empty Constructor and another Constructor (<code>String n, int[] tests, String g</code>).</p></li>
  <li><p>We were instructed to override the <code>computeGrade()</code> method so that an UnderGrad() student must get a 70 or higher to pass. </p></li>
  </ol>
  
  <p>The third class is the <code>GradStudent</code> a subclass of Student. </p>
  
  <ol>
  <li><p>We have to create 1 instance variable, <code>int MyGradID</code>, and an empty constructor, which calls super, and set the IDs to 0. </p></li>
  <li><p>And another constructor <code>(String n, int[] tests, String g, int id)</code>- Remember to call the super constructor and set ID. </p></li>
  <li><p><strong>Again where I am having challenges.</strong> We had to write the method <code>getId()</code>, to return the ID number. Again we needed to override the <code>computeGrade()</code> method And, if the average is greater than or equal to 65, the grade is a "Pass". Otherwise it is a "Fail". But if the test average is higher than 90, the grade should be "Pass with distinction".</p></li>
  </ol>
  
  <p>I have great difficulty with this task. I attached the <code>GradStudent</code> code. Can you find the errors please? I don't fully understand how to override the superclass private instance variables.</p>
  
  <pre><code>public class GradStudent extends Student {
  
      private int MyGradID;
  
      public void GradStudent() {
          super();
          MyGradID = 0;
      }
  
      public void GradStudent(String n, int[] tests, String g, int id) {
          super(n, tests, g);
          MyGradID = id;
      }
  
      public int getId() {
          return MyGradID;
      }
  
      @Override public void computeGrade() {
          if (testScores.getTestAverage() &gt;= 65) {
              super.setGrade("Pass");
          } else if (testScores.getTestAverage() &gt; 90) {
              grade = "Pass with distinction";
          }
      }
  }
  </code></pre>
  
  <p>This is my <code>Student class</code>. I'm not sure if I am referencing my super class correctly, so I am adding it. Hopefully you can explain it to me.</p>
  
  <pre><code>public class Student {
      private String name;
      private int[] testScores = new int[3];
      private String grade;
  
      public Student() {
          name = "";
          grade = "";
          testScores[0] = 0;
          testScores[1] = 0;
          testScores[2] = 0;
      }
  
      public Student(String n, int[] tests, String g) {
          name = n;
          testScores = tests;
          grade = g;
      }
  
      public String getName() {
          return name;
      }
  
      public String getGrade() {
          return grade;
      }
  
      public void setGrade(String newGrade) {
          grade = newGrade;
      }
  
      public int getTestAverage() {
          int average = 0;
          int count = 0;
          for (int testScore : testScores) {
              count++;
              average = average + testScore;
          }
          return average / testScores.length;
      }
  
      public void computeGrade() {
          grade = "Fail";
          if (this.getTestAverage() &gt;= 65) {
              grade = "Pass";
          }
      }
  }
  </code></pre>