In: Computer Science
DESCRIPTION
Create a program to calculate and print basic stats on a set of a given input values representing students' scores on an exam.
1) Ask the user for the total number of exam scores to be input (assume a positive integer will be given).
2) Create an array to hold all the exam scores and then get all the scores from input to put into the array. For example, if the user input 10 in step (1) then you should create an array to hold 10 double values (each of the 10 exam scores) and ask the user for the 10 values, one-by-one, to put in each spot.
3) Calculate and print the average (mean) score.
4) Print out a table displaying the number of each letter grade in the set of scores. Assign grades of A for scores of 90 and above, B for scores of 80 and above (but below 90), C for scores of 70 and above (but below 80), D for scores of 60 and above (but below 70), and F for scores below 60.
Sample output of program:
How many exam scores?
10
Enter the 10 exam scores:
95.6
98
100
96
84.2
82
80
77
66
62.1
Average score: 84.09
Grade - Count:
A - 4
B - 3
C - 1
D - 2
F - 0
Starter Code:-
import java.util.Scanner;
public class ExamStats {
public static void main(String[] args) {
//TODO: Complete the program
}
}
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new java program with name "ExamStats.java" is created, which contains following code.
ExamStats.java :
import java.util.Scanner;
public class ExamStats {
public static void main(String[] args) {
//creating object of Scanner
class
Scanner sc=new
Scanner(System.in);
//Asking user to enter number of
Scores
System.out.print("Enter Number of
exam scores : ");
//reading exam scores
int examScore=sc.nextInt();
//declaring array to store exam
scores
double [] examScores=new
double[examScore];
//using for loop to read and store
exam score in the array examScores
for(int
i=0;i<examScore;i++)
{
//asking to
enter exam scores
System.out.print("Enter "+(i+1)+" exam score : ");
//reading
score
examScores[i]=sc.nextDouble();
}
//declaring variables to count the
grades
int A=0,B=0,C=0,D=0,F=0;
double sum=0;
for(int
j=0;j<examScore;j++)
{
//calculating
sum
sum=sum+examScores[j];
//if exam score
is > 90
if(examScores[j]>=90)
{
A++;//increment count for grade A
}
//if exam score
is > 80 and <90
else
if(examScores[j]>80 && examScores[j] <90 )
{
B++;//increment count for grade B
}
//if exam score
is > 70 and <80
else
if(examScores[j]>70 && examScores[j] <80 )
{
C++;//increment count for grade C
}
//if exam score
is > 60 and <70
else
if(examScores[j]>=60 && examScores[j] <70 )
{
D++;//increment count for grade D
}
//if exam score
is < 60
else
if(examScores[j] <60 )
{
F++;//increment count for grade F
}
}
//display details
System.out.println("Average :
"+(sum/examScore));
//display grade and count
System.out.println("Grade\tCount");
System.out.println("A\t\t"+A);
System.out.println("B\t\t"+B);
System.out.println("C\t\t"+C);
System.out.println("D\t\t"+D);
System.out.println("F\t\t"+F);
}
}
======================================================
Output : Compile and Run above program to get the screen as shown below
Screen 1 :ExamStats.java
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.