I need your help to answer this question correctly. please also post pictures of
ID: 3592070 • Letter: I
Question
I need your help to answer this question correctly. please also post pictures of input and output as my professor needs it. I need to get it done correctly
Explanation / Answer
We are usign a hash map to store grade and gpa table.Below is the code
import java.util.*;
public class Grade{
public static void main(String []args){
HashMap<String,Double> symbol_table=new HashMap<String,Double>();
symbol_table.put("A+",4.33);
symbol_table.put("A",4.00);
symbol_table.put("A-",3.67);
symbol_table.put("B+",3.33);
symbol_table.put("B",3.00);
symbol_table.put("B-",2.67);
symbol_table.put("C+",2.33);
symbol_table.put("C",2.00);
symbol_table.put("C-",1.67);
symbol_table.put("D",1.00);
symbol_table.put("F",0.00);
int n,i;
String[] grade;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of grades");
n=sc.nextInt();
grade=new String[5];
System.out.println("Enter the grades");
for(i=0;i<n;i++)
grade[i]=sc.next();
double average=0;
for(i=0;i<n;i++)
{
System.out.println("GPA for Grade "+grade[i]+" is "+symbol_table.get(grade[i]));
average=average+symbol_table.get(grade[i]);
}
System.out.println("GPA after calculating Average is "+average/n);
}
}
First number of grade will be inputted ,followed by grades
Sample Input
4
A
A+
C+
B-
Sample Output