write a program to read in a list of exam scores (integer percentage in the range 0 TO 100)
and to output the total number of grades as well as the number of grades in each letter- grade category (90-100=A, 80-89=B, 70-79=C, 60-69=D and 0-59=F) and what percentage of the total grades each letter grade represents. The end of the input is indicated by a negative score as a sentinel value.(the negative value is issued only to end input from the user, so do not use it in the calculation. For example if the input is
98
87 the output could look something like this:
87
86 Total number of grades = 14
85 Number of A's =1 which is 7.1%
85 Number of B's =4 which is 28.6%
78 Number of C's =6 which is 42.9%
73 Number of D's =2 which is 14.3%
72 Number of F's =1 which is 7.1%
72
70
66
63
50
-1
I NEED HELP TO UNDERSTAND MORE HOW TO DO THIS PROGRAM COZ I TRIED DOING IT BUT ONLY ONE OUTPUT IS GOING OUT.
import java.util.*;
import java.io.Console;
import java.util.Scanner;
import javax.swing.*;
public class NumberGrades
{
public static void main(String [] args)
{
Scanner keyboard= new Scanner(System.in);
Console c = System.console();
int score=0, n1;
String grade;
System.out.print("Please enter your score: ");
try {
score= Integer.valueOf(c.readLine());
} catch (NumberFormatException e) {
e.printStackTrace();
}
if(score>=90)
{
grade="A";
System.out.println("grade: " + grade);
}
else
if(score>=80)
{
System.out.print("Please enter your score: ");
grade= "B";
System.out.println("grade: " + grade);
}
else
if(score>=70)
{
grade = "C";
System.out.println("grade: " + grade);
}
else
if(score>=60)
{
grade= "D";
System.out.println("grade: " + grade);
}
else
if(score<=59)
{
grade ="F";
System.out.println("grade: " + grade);
}
else
grade= "X";