Any help would be very much appreciated! Having some problems with this program!
ID: 3551074 • Letter: A
Question
Any help would be very much appreciated! Having some problems with this program!
Using multidimensional arrays, write a java program that reads student's grades for three test from a file and calculuates: each student's average, the highest and lowest, and average test score for each of the three tests.
store each students test scores in one row a matrix (2D array)
the first entry in the file will be the number of students
the following numbers in the file will be in "column major form" that is, all test one scores (together) followed by all test two scores together then followed by all test three scores.
Output:
Student Test 1 Test 2 Test 3 Average
1 80 90 71 80.3
2 90 80 100 90.0
3 67 70 75 70.6
(all other student data here)
Highest 98 90 100
Lowest 60 53 70
Average 80.6 86.54 90.7 85.33
Explanation / Answer
import java.util.Scanner;
class Average
{
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter no of students");
int number = scanner.parseInt(nextInt);
Double arr = new Double[number][4];
for(int i = 0; i < number; i++)
{
sum = 0;
for (int j = 0; j < 3; j++)
{
System.out.println("Enter marks of test " + (j+1) + " of student " + (i+1));
arr[i][j] = scanner.parseDouble(nextDouble);
sum += arr[i][j];
}
arr[i]i3] = sum/3;
}
System.out.println(" Student Test 1 Test 2 Test 3 Average");
for(int i = 0; i < number; i++)
{
System.out.print((i+1));
for (int j = 0; j < 4; j++)
{
System.out.print( " " + arr[i][j]);
}
System.out.println();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.