title: Final Grade Calculator in java
body: <p>This is a personal project, just trying to create a program to calculate my final grade and to the best of my knowledge I thought I did everything right, here is my entire program updated with working code:</p>
  
  <p><strong>FinalGradeCalculator:</strong></p>
  
  <pre><code>import java.io.*;
  import java.util.Scanner;
  public class FinalGradeCalculator {
      public static final String readInFile = "MUSC110grades.txt";
      public static void main(String[] args) {
          try
          {
              Scanner readFile = new Scanner(new File(readInFile));
              String longString = "";
              while(readFile.hasNextLine())
              {
                  longString = longString.concat(readFile.nextLine()+" ");
              }
              readFile.close();
              int indexQuiz = longString.indexOf("Quizzes");
              int indexConcertReports = longString.indexOf("Concert Reports");
              int indexMidterm = longString.indexOf("Midterm");
              int indexFinal = longString.indexOf("Final");
              int indexEnd = longString.indexOf("End");
              //Quiz
              String quiz = longString.substring(indexQuiz+8, indexConcertReports);
              String[] quizList = quiz.split(" ");
              int quizScores = 0;
              for(int i=0;i&lt;quizList.length;i++)
                  quizScores += Integer.parseInt(quizList[i]);
              //Concert Report
              String cR = longString.substring(indexConcertReports+16, indexMidterm);
              String[] cRList = cR.split(" ");
              int cRScores = 0;
              for(int i=0;i&lt;cRList.length;i++)
                  cRScores += Integer.parseInt(cRList[i]);
              //Midterm
              String midterm = longString.substring(indexMidterm+8, indexFinal-1);
              int midtermScores = Integer.parseInt(midterm);
              //Final
              String finals = longString.substring(indexFinal+6, indexEnd-1);
              int finalsScores = Integer.parseInt(finals);
  
              double quizAvg = Math.ceil(quizScores/quizList.length);
              System.out.println("Your Quiz Average is " + quizAvg);
              double cRAvg = Math.ceil(cRScores/cRList.length);
              System.out.println("Your Concert Report Average is " + cRAvg);
              double midtermGrade = Math.ceil(midtermScores);
              System.out.println("Your Midterm Grade is " + midtermGrade);
              double finalsGrade = Math.ceil(finalsScores);
              System.out.println("Your Finals Grade is " + finalsGrade);
              double totalGrade = Math.ceil(cRAvg*0.2 + quizAvg*0.35 + midtermGrade*0.2 + finalsGrade*0.25);
              System.out.println("Your Total Grade is " + totalGrade);
  
              if(totalGrade &gt;= 90)
                  System.out.println("Your final grade is A");
              else if(totalGrade &gt;= 85)
                  System.out.println("Your final grade is B+");
              else if(totalGrade &gt;= 80)
                  System.out.println("Your final grade is B");
              else if(totalGrade &gt;= 75)
                  System.out.println("Your final grade is C+");
              else if(totalGrade &gt;= 70)
                  System.out.println("Your final grade is C");
              else if(totalGrade &gt;= 65)
                  System.out.println("Your final grade is D+");
              else if(totalGrade &gt;= 60)
                  System.out.println("Your final grade is D");
              else
                  System.out.println("your final grade is F");
          }
          catch(Exception e)
          {
              System.out.println(e);
          }
      }
  }
  </code></pre>
  
  <p>When I run the program it gives me a number format exception: <code>java.lang.NumberFormatException: For input string: "70 "</code>. here is the text file:</p>
  
  <p><strong>MUSC110grades.txt:</strong></p>
  
  <pre><code>Quizzes
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  0
  0
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  0
  0
  100
  100
  0
  0
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  100
  Concert Reports
  100
  100
  90
  90
  Midterm
  72
  Final
  70
  End
  </code></pre>
  
  <p>Now I've looked up what a number format exception is but I don't understand why the number <code>50</code> is not an integer. I need help solving this issue, it may have something to do with the index's maybe. I'm not sure.</p>