title: Symbol table in Java
body: <p>I'm trying to write a program for manipulating a symbol table in Java. I've used a linked list data structure as a way to represent my symbol table; the linked list(singly) has a key,value associated to that key, and a pointer to the next point. The linked list also provides to the user the function of inserting a new node to the list. It seems that my implementation for the linked list class is going well, but when I was trying write a main program to test that, I've got some problems. Despite the errors that I managed somehow to handle them with exceptions, there is a logical error in my code. Here is the piece of code that I wrote and the output as well:</p>
  
  <pre><code>import java.util.Scanner;
  public class Test_GPA {
  public static void main(String[]args){
  
       // create symbol table of grades and values
      GPA&lt;String, Double&gt; grades = new GPA&lt;String, Double&gt;();
      grades.put("A",  4.00);
      grades.put("B",  3.00);
      grades.put("C",  2.00);
      grades.put("D",  1.00);
      grades.put("F",  0.00);
      grades.put("A+", 4.33);
      grades.put("B+", 3.33);
      grades.put("C+", 2.33);
      grades.put("A-", 3.67);
      grades.put("B-", 2.67);
     Scanner input = new Scanner(System.in);
     double numb =0; int i=0;
      double sum = 0.0;
     String grade;
     Double value;
     System.out.println("Please enter number of courses:");
     numb=input.nextInt();
     while(i&lt;numb){
         System.out.println("Please enter the grade for course"+(i+1)+":");
         grade = input.nextLine();
         value = grades.get(grade);
        try{
            sum += Double.valueOf(value);
        }catch(Exception e){}
         i++;
  
     }
     double gpa = sum/numb;
     System.out.println("GPA = "+gpa);
  </code></pre>
  
  <p>The problem is the code always skips the reading of the first entry by the user. For example, if I run this program and enter the number of courses to be 4, the result will be as shown:</p>
  
  <pre><code>Please enter number of courses:
  4
  Please enter the grade for course1:
  Please enter the grade for course2:
  A
  Please enter the grade for course3:
  A
  Please enter the grade for course4:
  A
  GPA = 3.0
  </code></pre>
  
  <p>I don't know actually where is the mistake that I've made. And of course by missing the reading of the first entry that leads to a wrong computation for the GPA. Please, is there anyone interested in showing me how to fix the error. I've tried almost everything i know and it still doesn't work. just FYI, this is the first time i program in Java. Thank you in advance.</p>