Question: In Java we were supsoed to create a program where it read a list of grades from a text file and then calculate a GPA

In Java we were supsoed to create a program where it read a list of grades from a text file and then calculate a GPA but im running into a error in the code below where im getting a null pointer exeption. im not sure here im going wrong and any help would be great.

package program1; import algs31.BinarySearchST; import stdlib.*;

public class ComputeGPA { public static void main(String[] args) { BinarySearchST gradePointsST = new BinarySearchST<>(); gradePointsST.put("A+", 4.33); gradePointsST.put("A", 4.00); gradePointsST.put("A-", 3.67); gradePointsST.put("B+", 3.33); gradePointsST.put("B", 3.00); gradePointsST.put("B-", 2.67); gradePointsST.put("C+", 2.33); gradePointsST.put("C", 2.00); gradePointsST.put("C-", 1.67); gradePointsST.put("D", 1.00); gradePointsST.put("F", 0.00);

double totalGradePoints = 0.0; int numGrades = 0;

StdIn.fromFile("data/a1grades.rtf");

while (!StdIn.isEmpty()) { String grade = StdIn.readString(); totalGradePoints += gradePointsST.get(grade); // running into errors here on this line. numGrades++; }

System.out.println("GPA = " + totalGradePoints / numGrades); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!