I need your help to answer 6question correctly. please also post pictures of inp
ID: 3592359 • Letter: I
Question
I need your help to answer 6question correctly. please also post pictures of input and output as my professor needs it. I need to get it done correctly
I am also attaching slides with it so that it's easy for you to answer
these are lectures slides which might b helpful to answer this. I'm posting this question for second time. please do attach pictures of input and output
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
GPA for Grade A is 4.0
GPA for Grade A+ is 4.33
GPA for Grade C+ is 2.33
GPA for Grade B- is 2.67
GPA after calculating Average is 3.3325