title: Calculate GPA for a student
body: <p>Create a Java program that will read an array of letter grades that belongs to a student named John, as follows : </p>
  
  <p>char John[] = {'A','B','A','C','F','B','A','D','A','C'};</p>
  
  <p>The grade points for each grade is as follows:</p>
  
  <p>A=4,B=3,C=2,D=1,F=0</p>
  
  <p>Your program is to read each elements inside the array, validate the letter grade (which must be A, B, C, D or F), match the grade with appropriate grade points, and display the Grade Point Average(GPA) for John. Your program is to stop processing when your reach the last index of the array.</p>
  
  <p>Here what i had tried but cannot get the right GPA.</p>
  
  <pre><code>public static void main(String [] args)
  {
  
      int gradepoint;
      char grade = ' ';
      double sum = 0;
  
      char John [] = {'A','B','A','C','F','B','A','D','A','C'};
  
      for (char c : John) {
      switch(c)
      {
      case 'A' : gradepoint = 4; break;
      case 'B' : gradepoint = 3; break;
      case 'C' : gradepoint = 2; break;
      case 'D' : gradepoint = 1; break;
      case 'F' : gradepoint = 0; break;
      }
      }
  
      for (int counter = 0; counter &lt; John.length; counter++) {
          sum += John[counter];
      }
      double gpa = sum/10;
  
      System.out.println("GPA : " + gpa );
  }
  </code></pre>
  
  <p>}</p>