Question
Write a java program where it asks the user to enter exam scores in the range 0 to 100. Enter a negative integer to indicate
Write a java program where it asks the user to enter exam scores in the range 0 to 100. Enter a negative integer to indicate the end of the input. Display the following statistics:
Total Numbers of scores
Total Number of each letter grade
Percentage of total for each letter grade
Range of scores: lowest and highest
Average Score
This is what I got so far. I am not sure how to get the percentage for each letter grade
import java.util.Scanner;
public class Practice7
{
public static void main (String [] args)
{
int gradeA = 0, gradeB = 0, gradeC = 0, gradeD = 0, gradeF = 0;
int count = 0;
double averageA = 0, averageB = 0, averageC = 0, averageD = 0, averageF = 0;
double averageScore = 0;
int minGrade = 100;
int maxGrade = 0;
double sum = 0;
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a list of exam scores in the range from 0 to 100");
System.out.println("Enter a negative scored to end the input");
int gradesInputed = keyboard.nextInt();
while(gradesInputed > 0)
{
count++; // to count how many inputed
if(gradesInputed >= 90 && gradesInputed <= 100)
gradeA++;
else if(gradesInputed>=80 && gradesInputed<=89)
gradeB++;
else if(gradesInputed>=70 && gradesInputed<=79)
gradeC++;
else if(gradesInputed>=60 && gradesInputed<=69)
gradeD++;
else if(gradesInputed>=0 && gradesInputed<=59)
gradeF++;
if(averageA > 0)
averageA = averageA / gradeA;
if(averageB > 0)
averageB = averageB / gradeB;
if(averageC > 0)
averageC = averageC / gradeC;
if(averageD > 0)
averageD = averageD / gradeD;
if(averageF > 0)
averageF = averageF / gradeF;
if(gradesInputed < minGrade)
minGrade = gradesInputed;
if(gradesInputed > maxGrade)
maxGrade = gradesInputed;
gradesInputed = keyboard.nextInt();
for(int i = 0; i <= count; i++)
{
sum = sum + gradesInputed;
}
averageScore = sum / count;
}
System.out.println(sum);
System.out.println("Total number of scores: " + count);
System.out.println("Total number of A's:"+ gradeA);
System.out.println("Total number of B's:"+ gradeB);
System.out.println("Total number of C's:"+ gradeC);
System.out.println("Total number of D's:"+ gradeD);
System.out.println("Total number of F's:"+ gradeF);
System.out.println();
System.out.println("Total percentage of A's:"+ averageA);
System.out.println("Total percentage of B's:"+ averageB);
System.out.println("Total percentage of C's:"+ averageC);
System.out.println("Total percentage of D's:"+ averageD);
System.out.println("Total percentage of F's:"+ averageF);
System.out.println();
System.out.println("The highest grade is: " + maxGrade);
System.out.println("The lowes grade is: " + minGrade);
System.out.println("The average score is: " + averageScore);
}
}
Step by Step Solution
3.36 Rating (162 Votes )
There are 3 Steps involved in it
Step: 1
Program Screenshots Sample Output import javautilScanner public class Practice7 public s...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started