Question

In: Computer Science

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 the average was 89.2%

In test 2........etc

Your main method should be modular.

Write a method that inputs the 5 names into an array (one dimensional), and returns this array to main

Write a method that inputs the 15 (integer) test grades into a (two-dimensional) array, and returns this array to main.

Write a method that calculates the students averages and stores them in an array , and returns this array to main

Write a method that calculates the average grade for each test and stores them in an array, and returns this array to main

Write a method that determines the highest grade for each test and stores this in an array , and returns this array to main. MAIN will print all the information. The printing could be done easily by the methods instead of having to store the information in an array, but this will give you practice in arrays and methods - all useful for the final exam.

Thanks a lot, please include the comments.

Solutions

Expert Solution

Full working code:

import java.util.Scanner;
public class TestScores {
    /*
    Take input all the names of the students from user and return that array
     */
    public static String[] inputNames()
    {
        Scanner sc = new Scanner(System.in);
        String names[] = new String[5];
        for(int i =0 ; i<5; i++)
        {
            names[i] = sc.next();
        }
        return names;
    }
    //Takes input test scores of 15 test. 3 Test for 5 students i.e 5 X 3 matrix
    public static int[][] testScores()
    {
        Scanner sc = new Scanner(System.in);
        int [][]scores = new int[5][3];
        for(int i = 0 ; i < 5 ; i++)
        {
            for(int j = 0 ; j < 3 ; j++)
            {
                scores[i][j] = sc.nextInt();
            }
        }
        return scores;
    }
    //Calculate average score of every students grade and returns that array
    public static double[] averageScores(int [][]scores)
    {
        double []avgScore = new double[5];
        for(int i = 0 ; i < 5 ; i++)
        {
            int sum = 0;
            for(int j = 0 ; j < 3 ; j++)
            {
                sum += scores[i][j];
            }
            avgScore[i] = sum/3;
        }
        return avgScore;
    }
    //Average test score of every 3 tests.
    public static double[] averageTestGrade(int [][]scores)
    {
        double []averageTestGrade = new double[3];
        for(int i = 0 ; i < 3 ; i++)
        {
            int sum = 0;
            for(int j = 0; j < 5 ; j++)
            {
                sum = sum + scores[j][i];
            }
            averageTestGrade[i] = sum/5;
        }
        return averageTestGrade;
    }
    //Returns the array of 3 elements with highest score in individual test
    public static int[] highestTestScore(int [][]scores)
    {
        int highestTestScore[] = new int[3];
        for(int i = 0 ; i < 3 ; i++)
        {
            int max = scores[0][i];
            for(int j = 1; j < 5 ; j++)
            {
                if(scores[j][i] > max)
                    max=scores[j][i];
            }
            highestTestScore[i] = max;
        }
        return highestTestScore;
    }
    //Driver Method where all the static method constructed above are being called wherever necessary
    public static void main (String[] args) {
        TestScores s = new TestScores();
        String []names = new String[5];
        names = s.inputNames();
        int testScores[][] = new int [5][3];
        testScores = testScores();
        double averageScores[] = new double[5];
        averageScores = averageScores(testScores);
        double averageTestGrade[] = new double[3];
        averageTestGrade = averageTestGrade(testScores);
        int highestTestScore[] = new int[3];
        highestTestScore = highestTestScore(testScores);
        //Display students grade
        for(int i = 0; i< 5; i++)
            System.out.println(names[i]+"'s average grade was "+averageScores[i]);
        //Display each test data
        for(int i = 0 ; i< 3 ; i++)
        {
            System.out.println("In Test "+(i+1)+" the highest grade was "+highestTestScore[i]+"% and the average was "+averageTestGrade[i]+"%");
        }
    }
}

Input:

Vijay Shivani Kanu Nishi Vivek
70 100 70
80 90 80
90 70 60
30 40 50
80 40 50

Output:

Vijay's average grade was 80.0
Shivani's average grade was 83.0
Kanu's average grade was 73.0
Nishi's average grade was 40.0
Vivek's average grade was 56.0
In Test 1 the highest grade was 90% and the average was 70.0%
In Test 2 the highest grade was 100% and the average was 68.0%
In Test 3 the highest grade was 80% and the average was 62.0


Related Solutions

Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment...
Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment Create a class GradesGraph that represents a grade distribution for a given course. Write methods to perform the following tasks: • Set the number of each of the letter grades A, B, C, D, and F. • Read the number of each of the letter grades A, B, C, D, and F. • Return the total number of grades. • Return the percentage of...
JAVA - Complete the directions in the 5 numbered comments import java.util.Scanner; /** * This program...
JAVA - Complete the directions in the 5 numbered comments import java.util.Scanner; /** * This program will use the HouseListing class and display a list of * houses sorted by the house's listing number * * Complete the code below the numbered comments, 1 - 4. DO NOT CHANGE the * pre-written code * @author * */ public class HouseListingDemo { public static void main(String[] args) { Scanner scan = new Scanner(System.in); HouseListing[] list; String listNumber, listDesc; int count =...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them into a Text File. The inputs are Student Name, Student Address and student Date of Birth. Also write a simple program that reads and display the input from the first program text file.
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three integer values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three int||eger values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Please show solution and comments for this data structure using java.​ Implement a program in Java...
Please show solution and comments for this data structure using java.​ Implement a program in Java to convert an infix expression that includes (, ), +, -, *,     and / to postfix expression. For simplicity, your program will read from standard input (until the user enters the symbol “=”) an infix expression of single lower case and the operators +, -, /, *, and ( ), and output a postfix expression.
Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
JAVA Write a program that will compare two names. The program prompts the user to enter...
JAVA Write a program that will compare two names. The program prompts the user to enter two names for a comparison. If the names are same, the program states that. If the names are different, the program converts both names to UPPERCASE, and compares then again. If they are equal, the programs displays a message stating that names are equal if CASE is ignored. Otherwise, the program prints names with a message that names are not equal.  Check also if there...
Write a complete Java program, including comments in both the main program and in each method,...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...
Write a complete Java program, including comments in both the main program and in each method,...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT