title: Computing Final Grade Using For Loops and Arrays in Java
body: <p>I am currently in a Pre-AP Computer Science class. Our teacher has assigned us a project due by midnight tonight. The project requires that you make a program that asks what your name is, how many grades you are entering, asks for your grades, averages your grades, then returns a letter value (e.g. A, B, C), along with your name (e.g. "Iqbal, Noor"). I seemingly had all my code worked out and was only having an out of bounds error when I entered my grades in. However, my teacher said that the only way to fix this error was to make a giant for loop and put the entirety of my code in it. It doesn't make sense to me, so if that is the case, could someone please explain it?</p>
  
  <p>If that is not the case, I would like to know what to do. I would not like someone to give me an answer, rather lead me in the process of thinking how I can move forward with this problem.</p>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>import java.util.*;
  public class Tester {
  public static void main (String[] args){
      //Prompt for first
      //Prompt for last
      //Prompt for # of assgmts to be averaged
      //for-loop = prompt to enter # grade until all grades are entered (use [])
      //loop through array again to calculate average
      //print info
      //prompt for multiple names and grades
      Scanner kbInput = new Scanner(System.in);
      System.out.println("How many students will you be entering?");
      int numOfStudents = kbInput.nextInt();
      String[] Students = new String[numOfStudents];
  
      int k;
      for(k = 0; k &lt; Students.length; k++){
          System.out.println("Enter your first name.");
          String first = kbInput.next();
          System.out.println("Enter your last name.");
          String last = kbInput.next();
          Students[k] = last + ", " + first;
      }
  
      String finalGrade = "";
      System.out.println("How many grades will you be entering?");
      int numOfGrades = kbInput.nextInt();
      int[] Grades = new int[numOfGrades];
      int sum = 0;
      int j;
      for (j = 0; j &lt; numOfGrades; j++){
          System.out.println("Enter your grades.");
          Grades[j] = kbInput.nextInt();
          sum+=Grades[j];
      }
      int average = sum/numOfGrades;
          if((average &gt;= 90) &amp;&amp; (average &lt;= 100)){
              finalGrade = "A";
          }
          else if((average &gt;= 80) &amp;&amp; (average &lt; 90)){
              finalGrade = "B";
          }
          else if((average &gt;= 75) &amp;&amp; (average &lt; 80)){
              finalGrade = "C";
          }
          else if((average &gt;= 70) &amp;&amp; (average &lt; 75)){
              finalGrade = "D";
          }
          else if(average &lt; 70){
              finalGrade = "F";
          }
          String[] letterGrade = new String[numOfStudents];
          int count;
          for(count = 0; count &lt; numOfStudents; count++){
              letterGrade[count] = finalGrade;
          }
      }
  }
  </code></pre>
  
  <p>EDIT: Here are the directions for the project: </p>
  
  <ol>
  <li>Create a new Java Project called FinalGrade with a single class called Tester.</li>
  <li>Prompt the user to enter a student’s first name, followed by another prompt to enter the student’s last name.</li>
  <li>Prompt the user to enter the number of assignments to be averaged (ex. 6).</li>
  <li>Using a for-loop, prompt the user to enter the numeric grade (whole numbers only) until the exact number of assignments for the student are entered. NOTE: The grades should be stored in an array.</li>
  <li>Loop back through the array of grades and calculate an average of the grades entered.</li>
  <li>Print the following information (in the order shown) on the screen…
  a.  Student’s Last Name
  b.  Student’s First Name
  c.  Student’s Final Grade (Displayed as a Letter Grade and not the Numeric Value)
  Example Output…
  Howard, Derek – A</li>
  </ol>
  
  <p>Going Beyond…
  1.  Alter your application to allow entry of multiple students and grades.</p>