Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to compute a GPA from letter grades. In Eclipse, create a packag

ID: 3882661 • Letter: W

Question

Write a program to compute a GPA from letter grades. In Eclipse, create a package called program1 (note the lowercase first letter), in which you will create a program called ComputeGPA.

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 stdlibpackage. 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.

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.00

Explanation / Answer

import java.io.*;
import java.util.*;

class SymbolEntry{
   public String letter;
   public double value;
}

public class ComputeGPA {
    public static void main(String[] args){
       int count = 0;
       double value = 0;

       SymbolEntry[] table = new SymbolEntry[11];
       for (int i = 0; i<11; i++){
           table[i] = new SymbolEntry();
       }

       table[0].letter = "A+";
       table[0].value = 4.33;
       table[1].letter = "A";
       table[1].value = 4.00;
       table[2].letter = "A-";
       table[2].value = 3.67;
       table[3].letter = "B+";
       table[3].value = 3.33;
       table[4].letter = "B";
       table[4].value = 3.00;
       table[5].letter = "B-";
       table[5].value = 2.67;
       table[6].letter = "C+";
       table[6].value = 2.33;
       table[7].letter = "C";
       table[7].value = 2.00;
       table[8].letter = "C-";
       table[8].value = 1.67;
       table[9].letter = "D";
       table[9].value = 1.00;
       table[10].letter = "F";
       table[10].value = 0.00;
       try {
          File file = new File("a1grades.txt");
          Scanner sc = new Scanner(file);
          while (sc.hasNext()){
              String str = sc.next();
              for (int i = 0; i<table.length; i++){
                  if (str.equals(table[i].letter)){
                     value = value + table[i].value;
                     count++;
                  }
              }
           }
       }
       catch (Exception e){
           e.printStackTrace();
       }
       double gpa = value/count;
       System.out.println("GPA =" + gpa);
       
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote