In: Computer Science
(JAVA) Write a program that maintains student test
scores in a two-dimesnional array, with the students identified by
rows and test scores identified by columns. Ask the user for the
number of students and for the number of tests (which will be the
size of the two-dimensional array). Populate the array with user
input (with numbers in {0, 100} for test scores). Assume that a
score >= 60 is a pass for the below.
Then, write methods for:
Computing the number of tests that each student
passed
Computing the number of students passed for each
test
The methods should accept a two-dimensional array as
one argument and a specific student number (for (a)) or a specific
test number (for (b)) as the other argument. The methods should
return the relevant counts.
Call the above methods (from main) by passing the two-dimensional
array that contains the test scores, for each student (for (a)) and
then for each test (for (b)). Print the counts.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Please enter number of students:");
int noOfStudents = input.nextInt();
System.out.print("Please enter number of Tests:");
int noOfTests = input.nextInt();
int[][] testScoresOfStudents = new
int[noOfStudents][noOfTests];
for(int nS = 0;nS<noOfStudents;nS++) {
System.out.println("\nTest scores of student"+nS+" :" );
for(int nT= 0 ; nT<noOfTests;nT++) {
System.out.print("Test "+nT+" score:" );
testScoresOfStudents[nS][nT] = input.nextInt();
}
}
System.out.println("Tests passed by student
0:"+testsPassedByAStudent(testScoresOfStudents,0));
System.out.println("No of students passed Test
0:"+studentsPassedAParticularTest(testScoresOfStudents,0));
}
public static int testsPassedByAStudent(int[][]
testScoresOfStudents,int studentId ) {
int count = 0;
for(int i =
0;i<testScoresOfStudents[studentId].length;i++) {
if(testScoresOfStudents[studentId][i]>=60)
++count;
}
return count;
}
public static int studentsPassedAParticularTest(int[][]
testScoresOfStudents,int testId ) {
int count = 0;
for(int i = 0;i<testScoresOfStudents.length;i++)
{
if(testScoresOfStudents[i][testId]>=60)
++count;
}
return count;
}
}