title: There is an error in my java coding when I put a grade percentage for my gradebook application
body: <p>I have an application that acts as a gradebook. However, in the console log when I type in a grade there seems to be an error. I was hoping someone could fix this to where I am able to put in a grade percentage and the error does not pop up.<code>enter code here</code></p>
  <p>Below is what the error says:java.lang.NumberFormatException: For input string: &quot;70%&quot;
  at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
  at java.lang.Integer.parseInt(Integer.java:580)
  at java.lang.Integer.parseInt(Integer.java:615)
  at Gradebook.getScores(Gradebook.java:45)
  at Gradebook.main(Gradebook.java:154)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)</p>
  <p>Here is my code:</p>
  <pre><code>import java.util.Scanner;
  public class Gradebook {
      //getNumStudents takes a Scanner object as parameter
      //the reader object lets us take user input
      public static int getNumStudents(Scanner reader){
          int numStudents = 0;
          //we get the number of students
          do{
             System.out.print(&quot;Enter number of students: &quot;);
             numStudents = Integer.parseInt(reader.nextLine());
             //we determine if the user input is valid
             //it should be greater than 0
             //because we don't want the number o students to be negative
             //if it is not valid then we keep taking inputs
             if(numStudents &gt; 0){
                 break;
             }else{
                 System.out.println(&quot;Please enter atleast 1 student.&quot;);
             }
          }while(true);
          System.out.println(&quot;================================================================================================================================================&quot;);
          //we return numStudents
          return numStudents;
      }
      //getScores takes our Scanner object again and the number student as parameter this time
      public static String[] getScores(Scanner reader, int numStudents){
          //we create an array of string studInfo
          //that will be returned containing the name, and scores of our students
          String[] studInfo = new String[numStudents];
          String name = &quot;&quot;;
          int quiz = 0;
          int assign = 0;
          int test1 = 0;
          int test2 = 0;
          //we use a for loop to keep taking student scores
          for(int i = 0; i &lt; numStudents; i++){
              //enter name
              System.out.print(&quot;Enter student &quot;+(i+1)+&quot; name: &quot;);
              name = reader.nextLine();
              //enter quiz, assignment, test1 and test2 scores
              //we also validate scores to not be negative
              //and not out of bounds
              do{
                  System.out.print(&quot;Enter Quiz Score (over 40): &quot;);
                  quiz = Integer.parseInt(reader.nextLine());
                  if(quiz &gt;= 0 &amp;&amp; quiz &lt;= 40){
                      break;
                  }else{
                      System.out.println(&quot;Please put a valid score.&quot;);
                  }
              }while(true);
              do{
                  System.out.print(&quot;Enter Assignment Score (over 30): &quot;);
                  assign = Integer.parseInt(reader.nextLine());
                  if(assign &gt;= 0 &amp;&amp; assign &lt;= 30){
                      break;
                  }else{
                      System.out.println(&quot;Please put a valid score.&quot;);
                  }
              }while(true);
              do{
                  System.out.print(&quot;Enter Midterm Test Score (over 55): &quot;);
                  test1 = Integer.parseInt(reader.nextLine());
                  if(test1 &gt;= 0 &amp;&amp; test1 &lt;= 55){
                      break;
                  }else{
                      System.out.println(&quot;Please put a valid score.&quot;);
                  }
              }while(true);
              do{
                  System.out.print(&quot;Enter Final Test Score (over 65): &quot;);
                  test2 = Integer.parseInt(reader.nextLine());
                  if(test2 &gt;= 0 &amp;&amp; test2 &lt;= 65){
                      break;
                  }else{
                      System.out.println(&quot;Please put a valid score.&quot;);
                  }
              }while(true);  
              //after we get the name and student's score
              //we put it in a string 
              studInfo[i] = name+ &quot; &quot; +quiz+ &quot; &quot; +assign+ &quot; &quot; +test1+ &quot; &quot; +test2;
              System.out.println();
          }
          //return the studInfo
          return studInfo;
      }
      //our displayGrade takes String array as parameter
      public static void displayGrade(String[] studInfo){
          //this is our header for our formatted table
          System.out.println(&quot;================================================================================================================================================&quot;);
          System.out.println(String.format(&quot;%-30s%-10s%-12s%-15s%-12s%-10s%-15s%s&quot;, &quot;Name&quot;, &quot;Quiz&quot;, &quot;Assignment&quot;, &quot;Midterm Test&quot;, &quot;Final Test&quot;, &quot;Average&quot;, &quot;Letter Grade&quot;, &quot;Status&quot;));
          System.out.println(&quot;================================================================================================================================================&quot;);
          //we go through our array of string
          for(int i = 0; i &lt; studInfo.length; i++){
              //the split method returns an array of strings
              //that are split by a delimeter
              String[] data = studInfo[i].split(&quot; &quot;);
              //we sum up the scores
              //but we have to parse it to double first
              //to get the closest sum
              double sum = ((Double.parseDouble(data[1]) / 40.0) * 100.0) * 0.15;
              sum += ((Double.parseDouble(data[2]) / 30.0) * 100.0) * 0.15;
              sum += ((Double.parseDouble(data[3]) / 55.0) * 100.0) * 0.3;
              sum += ((Double.parseDouble(data[4]) / 65.0) * 100.0) * 0.4;
              //after that we round the sum and convert it to int and put it in average
              int average = (int) Math.round(sum);
              char letterGrade = ' ';
              //we get the letter grade using a nested if else
              if(average&gt;=0 &amp;&amp; average&lt;=59){
                  letterGrade = 'F';
              }else if(average&gt;=60 &amp;&amp; average&lt;=69){
                  letterGrade = 'D';
              }else if(average&gt;=70 &amp;&amp; average&lt;=79){
                  letterGrade = 'C';
              }else if(average&gt;=80 &amp;&amp; average&lt;=89){
                 letterGrade = 'B';
              }else if(average&gt;=90 &amp;&amp; average&lt;=100){
                  letterGrade = 'A';
              }
              String status = &quot;&quot;;
              //we determine the status of our student here
              //using switch case 
              //if the leter grade is f then he fails
              //if the case is D then he needs to go to remedial class
              //otherwise they pass
              switch(letterGrade){
                  case 'F':
                      status = &quot;Fail&quot;;
                      break;
                  case 'D':
                      status = &quot;Remedial&quot;;
                      break;
                  case 'A': case 'B': case 'C':
                      status = &quot;Pass&quot;;
                      break;
              }
              //we displat student information
              System.out.println(String.format(&quot;%-30s%-10s%-12s%-15s%-12s%-10d%-15c%s&quot;, data[0], data[1], data[2], data[3], data[4], average, letterGrade, status));
          }
          System.out.println(&quot;================================================================================================================================================&quot;);
       
      }
    
      public static void main(String[] args) {
          Scanner reader = new Scanner(System.in);
          
          displayGrade(getScores(reader, getNumStudents(reader)));
      }    
  }
  </code></pre>