Write a program using JOptionPane to read a list of exam scores given as integer
ID: 3625015 • Letter: W
Question
Write a program using JOptionPane to read a list of exam scores given as integer percentages in the range 0 to 100. Display the total number of grades and the number of grades in eachletter-grade category as follows: 90 to 100 is an A, 80 to 89 is a B, 70 to 79 is a C, 60 to 69 is a D, and 0 to 59 is an F. Use a negative score as a sentinel value to indicate the end of the input. (The negative value is used only to end the loop, so do not use it in the calculations.) For example, if the input is
98 87 86 85 85 78 73 72 72 72 70 66 63 50 -1
the output would be
Total number of grades = 14 Number of A's = 1 Number of B's = 4 Number of C's = 6
Number of D's = 2 Number of F's = 1
Explanation / Answer
public static void main(String[] args)
{
int a=0, b=0, c=0, d=0, f=0;
int total = 0;
while(true)
{
int score = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter exam score: "));
total++;
if(score >= 90)
a++;
else if(score >= 80)
b++;
else if(score >= 70)
c++;
else if(score >= 60)
d++;
else if(score >= 0)
f++;
else
break;
}
JOptionPane.showMessageDialog(null, "Total number of grades: "+total+" Number of A's = "+a+" Number of B's = "+b+" Numer of C's = "+c+" Number of D's = "+d+" Number of F's = "+f+" ", "Grades", JOptionPane.INFORMATION_MESSAGE);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.