Write a program called ComputeGPA to compute a GPA from letter grades. Write the
ID: 3874630 • Letter: W
Question
Write a program called ComputeGPA to compute a GPA from letter grades. Write the program so that it:
Declares and creates a symbol table using the algs31.BinarySearchST class;
Fills that symbol table with the following key-value pairs:
Reads a sequence of letter grades from a file called a1grades.txt using standard input, that is, using the method fromFile in the class StdIn in the stdlib package. As each grade is read, the program accumulates a total number of grade points by using the symbol table to convert a letter grade to a point value;
Computes and prints the GPA.
You may assume that the letter grades are separated from each other with whitespace. Create your own test file called a1grades.txt and place it in the data directory. Remember that your program will open it using the pathname data/a1grades.txt. Do not submit your test file.
PLEASE NOTE: Do not copy any code from the algs31.BinarySearchST class. You will have a single line in your program that declares and creates an empty symbol table and then you will need to call the instance methods put and get.
Letter Points A+ 4.33 A 4.00 A- 3.67 B+ 3.33 B 3.00 B- 2.67 C+ 2.33 C 2.00 C- 1.67 D 1.00 F 0.00Explanation / Answer
Solution to given problem is provided below. Sample execution output is also provided for reference.
File: ComputeGPA.java
Sample Input:
$ cat a1grades.txt
A+ B C- D F
Sample Output:
GPA = 2.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.