P
Panthereal
I need help modifying the following code that contains a student id
and four scores. I need to setup a double-scripted array and then
compute the average score for each student, min, max, mean and median
scores for the group and Print the statistics as follows:
Students [1] [2] [3] [4] Average:
2272 126 169 194 177 166.5
3375 163 188 189 185
4456 171 190 186 198
Lowest Score = 126
Highest Score = 198
Overall Average =
Mediam Score =
Here is what I have so far but its missing some needed code:
import java.awt.*;
public class DoubleArray extends JApplet {
int grades[][] = {{2772,126,169,194,177},
{3375,163,188,189,185},
{4456,171,190,186,198} };
int students, exams;
String output;
JTextArea outputArea;
public void init()
{
students=grades.length;
exams = grades[ 0 ].length;
outputArea = new JtextArea();
Container container = getContentPane();
container.add(outputArea);
output = "The array is:\n";
buildString();
output += "\n\nLowest grade: " + minimum() +
"\nHighest grade: " + maximum() + "\n";
for (int counter = 0; counter < students; counter++)
output += "\nAverage for student" + counter + "is"+
average(grades[counter]);
outputArea.setFont(
new Font("Courier", Font.PLAIN, 12));
outputArea.setText(output);
}
public int minimum()
{
int lowGrade = grades[0][0];
for (int row=0; row < students; row++)
for (int column = 0; column < exams; column++)
if (grades[row][column]<lowGrade)
lowGrade = grades[row][column];
return lowGrade;
}
public int maximum()
{
int highGrade = grades[0][0];
for (int row=0; row < students; row++)
for (int column = 0; column < exams; columns++)
if (grades[row][column] > highGrade)
highGrade = grades[row][column];
return highGrade;
}
public double average(int setOfGrades[])
{
int total = 0;
for (int count = 0; count < setOfGrades.length; count++)
total += setOfGrades[count];
return(double)total / setOfGrades.length;
}
public void buildString()
{
output += " ";
for (int counter = 0; counter < exams; counter++)
output +="[" + counter + "] ";
for (int row = 0; row < students; row++) {
output += "\ngrades[" + row + "] ";
for(int column = 0; column < exams; column++)
output += grades[row][column] + " ";
}
}
}
and four scores. I need to setup a double-scripted array and then
compute the average score for each student, min, max, mean and median
scores for the group and Print the statistics as follows:
Students [1] [2] [3] [4] Average:
2272 126 169 194 177 166.5
3375 163 188 189 185
4456 171 190 186 198
Lowest Score = 126
Highest Score = 198
Overall Average =
Mediam Score =
Here is what I have so far but its missing some needed code:
import java.awt.*;
public class DoubleArray extends JApplet {
int grades[][] = {{2772,126,169,194,177},
{3375,163,188,189,185},
{4456,171,190,186,198} };
int students, exams;
String output;
JTextArea outputArea;
public void init()
{
students=grades.length;
exams = grades[ 0 ].length;
outputArea = new JtextArea();
Container container = getContentPane();
container.add(outputArea);
output = "The array is:\n";
buildString();
output += "\n\nLowest grade: " + minimum() +
"\nHighest grade: " + maximum() + "\n";
for (int counter = 0; counter < students; counter++)
output += "\nAverage for student" + counter + "is"+
average(grades[counter]);
outputArea.setFont(
new Font("Courier", Font.PLAIN, 12));
outputArea.setText(output);
}
public int minimum()
{
int lowGrade = grades[0][0];
for (int row=0; row < students; row++)
for (int column = 0; column < exams; column++)
if (grades[row][column]<lowGrade)
lowGrade = grades[row][column];
return lowGrade;
}
public int maximum()
{
int highGrade = grades[0][0];
for (int row=0; row < students; row++)
for (int column = 0; column < exams; columns++)
if (grades[row][column] > highGrade)
highGrade = grades[row][column];
return highGrade;
}
public double average(int setOfGrades[])
{
int total = 0;
for (int count = 0; count < setOfGrades.length; count++)
total += setOfGrades[count];
return(double)total / setOfGrades.length;
}
public void buildString()
{
output += " ";
for (int counter = 0; counter < exams; counter++)
output +="[" + counter + "] ";
for (int row = 0; row < students; row++) {
output += "\ngrades[" + row + "] ";
for(int column = 0; column < exams; column++)
output += grades[row][column] + " ";
}
}
}