Question Create a Java application that contains methods to display statistics f
ID: 644957 • Letter: Q
Question
Question
Create a Java application that contains methods to display statistics for the numbers in an array.
The main method has been written for you. Upload ArrayStatistics.java from Moodle and complete the program by writing the following methods.
fillArray Method: Read the grades from a file named ExamScores.txt. The first number in the file is the number of exams follows by the exam scores. Create an array of the size indicated and fill it with exam scores from the file. After the exams are loaded, sort the array. Return the array to the calling method.
displayGrades Method: Receive the array as an argument and display the count for each letter grade (A, B, C, D, F). Letter grades are determined as follows:
Score Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F
frequencyChart Method: Receive the array as an argument and display a frequency chart for each exam score in the array. Display an asterisk for each distinct score found.
getMode Method: Receive the array as an argument and return the mode. If there are duplicate numbers for the mode, simply return the first number.
getAverage Method: Receive the array as an argument and return the average of exam scores found in the array.
getStandardDeviation: Receive the array and the average as arguments and return the standard deviation. Use the formula for standard deviation shown in exercise 7.11 on page 278 of the text.
Upload the ExamScores.txt file from Moodle and use it for the input in your assignment.
There are 32 exam scores
Frequency Chart
62 **
66 *
68 *
70 *
71 *
72 *
75 **
77 ***
80 *
83 *
85 ***
86 *
87 ***
88 *
89 **
90 *
91 *
94 ****
95 *
96 *
Mode 94
Average 82.21875
Standard Deviation 10.02
Letter Grade Summary
A 8
B 12
C 8
D 4
F 0
Program output should look like this:
Here is the main program given ...
import java.util.Arrays;
import java.util.Scanner;
import java.io.File;
public class ArrayStatistics
{
public static void main(String[] args) throws Exception
{
// Array to be used for statistics
int[] examScores;
int mode;
double average;
double standardDeviation;
examScores = fillArray();
if(examScores == null)
{
System.out.println("Error using exam file data");
}
else
{
System.out.println("There are " + examScores.length + " exam scores");
frequencyChart(examScores);
mode = getMode(examScores);
System.out.println(" Mode " + mode);
average = getAverage(examScores);
System.out.println("Average " + average);
standardDeviation = getStandardDeviation(examScores, average);
System.out.printf("Standard Deviation %.2f ", standardDeviation);
displayGrades(examScores);
}
}
}
There are 32 exam scores
Frequency Chart
62 **
66 *
68 *
70 *
71 *
72 *
75 **
77 ***
80 *
83 *
85 ***
86 *
87 ***
88 *
89 **
90 *
91 *
94 ****
95 *
96 *
Mode 94
Average 82.21875
Standard Deviation 10.02
Letter Grade Summary
A 8
B 12
C 8
D 4
F 0
Explanation / Answer
import java.io.File;
import java.util.List;
import java.util.Scanner;
class ArrayStatistics
{
String [] codes = new String[99];
int i = 0;
int getAverage(int[] array)
{
int sum=0,avg;
for(int i=1;i<11;i++)
{
sum=sum+array[i];
}
avg=sum/array[0];
return avg;
}
int getMode(int[] array)
{
int count=0;
for(int i=1;i<=11;i++)
{
for(int j=i+1;j<11;j++)
{
if(array[i]==array[j])
count++;
}
}
return count;
}
int[] fillArray()
{
int[] es=new int[50];
try
{
Scanner inFile1 = new Scanner(new File("C:/Program Files/Java/jdk1.6.0_18/bin/ExamScores.txt"));
while(inFile1.hasNext())
{
codes[i] = inFile1.nextLine();
i++;
}
for(int j=0;j {
es[j]=Integer.parseInt(codes[j]);
}
}
catch(Exception e){System.out.println(e);}
return es;
}
public static void main(String[] args) throws Exception
{
ArrayStatistics a=new ArrayStatistics();
int[] examScores=a.fillArray();
int mode,average;
//Displaying the elements of the array
for(int i=0;i<11;i++)
System.out.println(""+examScores[i]);
if(examScores == null)
{
System.out.println("Error using exam file data");
}
else
{
mode = a.getMode(examScores);
System.out.println(" Mode " + mode);
average = a.getAverage(examScores);
System.out.println("Average " + average);
}
}
}
/*
// Array to be used for statistics
int mode;
double average;
double standardDeviation;
examScores = fillArray();
{
System.out.println("There are " + examScores.length + " exam scores");
frequencyChart(examScores);
standardDeviation = getStandardDeviation(examScores,average);
System.out.printf("Standard Deviation %.2f ", standardDeviation);
displayGrades(examScores);
}
}
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.