Question

(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...

(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. Expert Answer

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class StudentTestScores {
  
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("How many students: ");
int nStudents = Integer.parseInt(sc.nextLine().trim());
System.out.print("How many test scores for each student: ");
int nTests = Integer.parseInt(sc.nextLine().trim());
  
int studentsTests[][] = new int[nStudents][nTests];
  
System.out.println("\nEnter the test scores for each student:");
for(int i = 0; i < nStudents; i++)
{
System.out.println("Student " + (i + 1) + ": ");
for(int j = 0; j < nTests; j++)
{
studentsTests[i][j] = Integer.parseInt(sc.nextLine().trim());
}
System.out.println();
}
System.out.println();
  
// METHOD 1
int studentNumber = 1; // sample test
studentNumber--;
if(studentNumber < 0)
studentNumber = 0;
  
int testsEachStudentPassed = NTestsEachStudentPassed(studentsTests, studentNumber);
System.out.println("Number of tests Student " + (studentNumber + 1) + " passed = " + testsEachStudentPassed);
  
// METHOD 2
int testNumber = 2; // sample test
testNumber--;
if(testNumber < 0)
testNumber = 0;
  
int studentsEachTestPassed = NStudentsEachTestPassed(studentsTests, testNumber);
System.out.println("Number of students passed Test " + (testNumber + 1) + " = " + studentsEachTestPassed);
}
  
// this method takes the 2-d array and a student number as input
// and returns the number of tests the student passed for
private static int NTestsEachStudentPassed(int students[][], int studentNumber)
{
int count = 0;
  
if(studentNumber < 0 || studentNumber > students.length)
System.out.println("\nInvalid student number!");
else
{
for(int i = 0; i < students[studentNumber].length; i++)
{
if(students[studentNumber][i] >= 60)
count++;
}
}
  
return count;
}
  
// this method takes the 2-d array and a test number as input
// and returns the number of students passed for that test number
private static int NStudentsEachTestPassed(int students[][], int testNumber)
{
int count = 0;
  
if(testNumber < 0 || testNumber > students[0].length)
System.out.println("\nInvalid test number!");
else
{
for(int i = 0; i < students.length; i++)
{
if(students[i][testNumber] >= 60)
count++;
}
}
  
return count;
}
}

********************************************************************* SCREENSHOT ******************************************************

run: How many students: 3 How many test scores for each student: 5 Enter the test scores for each student: Student 1: Student

Add a comment
Know the answer?
Add Answer to:
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following program that reads students’ test scores into an array and prints the contents of the array. You will add more functions to the program. The instructions are given below.

    Consider the following program that reads students’ test scores into an array and prints the contents of the array.   You will add more functions to the program.  The instructions are given below.              For each of the following exercises, write a function and make the appropriate function call in main.Comments are to be added in the program. 1.       Write a void function to find the average test score for each student and store in an array studentAvgs. void AverageScores( const int scores[][MAX_TESTS],                       int...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • Java Programming (use jGrasp if not thats fine) Write a Two classes one class that creates...

    Java Programming (use jGrasp if not thats fine) Write a Two classes one class that creates a two-dimensional 2 rows by 3 columns double array. This class will have a separate method for the user to populate the array with data values. The other class that has the following methods:   getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array.   getAverage. This method should accept a two-dimensional array...

  • IN JAVA WITH COMMENTS, The assignment: This program inputs the names of 5 students and the...

    IN JAVA WITH COMMENTS, The assignment: This program inputs the names of 5 students and the (integer) grades they earned in 3 tests. It then outputs the average grade for each student. It also outputs the highest grade a student earned in each test, and the average of all grades in each test. Your output should look like this: Mary's average grade was 78.8% Harry's average grade was 67.7% etc... : In test 1 the highest grade was 93% and...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • CSC888 has 4 people. Each person needs to take 3 tests. Create a 4-by-3 two-dimensional array...

    CSC888 has 4 people. Each person needs to take 3 tests. Create a 4-by-3 two-dimensional array to store the test scores. Ask the user to enter test scores one at a time to populate this array. Once the whole array is filled, do the following two things. (1) For each student, display her test scores and the average of the three tests. (2) For each test, display student scores and the average of the four students. The following shows a...

  • DESCRIPTION Complete the program using Java to read in values from a text file. The values...

    DESCRIPTION Complete the program using Java to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows)...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT