Question

In: Computer Science

Java: Declare a two-dim array that represents five students with four test scores. Assign 100 for...

Java:

Declare a two-dim array that represents five students with four test scores.

Assign 100 for all tests to all students.

Change the 3rd student’s test 2 to 50.

Change the last student’s last test to 87

Print out all test scores.

Calculate the total points of all tests of all students

Solutions

Expert Solution

//Java code

public class Main {
    public static void main(String[] args)
    {
        /**
         * Declare a two-dim array that represents five students with four test scores.
         */
        String[][] array = new String[5][5];
        /**
         * Assign 100 for all tests to all students.
         */

        for (int i = 0; i <array.length ; i++) {
            array[i][0]="Student"+(i+1);
            for (int j = 1; j <array[i].length ; j++) {
                array[i][j] = "100";
            }
        }
        //Change the 3rd student’s test 2 to 50.
        array[2][2] = "50";
        //Change the last student’s last test to 87
        array[4][4] = "87";
        System.out.println("\n===========================================================================");
        //heading
        System.out.println(String.format("%10s %10s %10s %10s %10s","Student","Score1","Score2","Score3","Score4"));
        //Print out all test scores.
        for (int i = 0; i <array.length ; i++) {

            for (int j = 0; j <array[i].length ; j++) {
                System.out.print(String.format("%10s",array[i][j]));
            }
            System.out.print("\n");
        }
        //Calculate the total points of all tests of all students
        int[] sum = new int[5];
        for (int i = 0; i <array.length ; i++) {

            for (int j = 1; j <array[i].length ; j++) {
                sum[i]+=Integer.parseInt(array[i][j]);
            }
        }
        System.out.println("\n===========================================================================");
        //Print report
        //heading
        System.out.println(String.format("%10s %10s %10s %10s %10s %10s","Student","Score1","Score2","Score3","Score4","Total"));
        for (int i = 0; i <array.length ; i++) {

            for (int j = 0; j <array[i].length ; j++) {
                System.out.print(String.format("%10s ",array[i][j]));
            }
            System.out.print(String.format("%10s ",sum[i]));
            System.out.print("\n");
        }
    }
}

//output

//If you need any help regarding this solution ......... please leave a comment ........ thanks


Related Solutions

(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...
Unix Create a script that will declare an array and assign four values from the command...
Unix Create a script that will declare an array and assign four values from the command line. 1. Use these four values - Paul, Ringo, George, John, - in that order 2. Display the content of the array, displaying the values in this format and this order The first array value is "John" The second array value is "Paul" The third array value is "George" The fourth array value is "Ringo"
In Java form Declare and assign a char variable called myLetter to z. Write a Java...
In Java form Declare and assign a char variable called myLetter to z. Write a Java statement that makes myLetter uppercase. Write a java statement that finds out if myLetter is a digit. Write a java statement that finds out if myLetter is an upper case letter. Assume myLetter = ‘Z’; What is the output for System.out.print(myLetter++); Assume myLetter = ‘Z’; What is the output for System.out.print(++myLetter); Assume myLetter = ‘Z’; What is the output for System.out.print(myLetter--); What happens when...
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an...
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an integer pointer p. 3. Let p pointing to the array a[ ]. 4. Use p (you have to use p) to put 0 into the first element of this array, 2 into the second element, 4 into the 3rd element, 6 into the 4th element, ... 198 into the 100th element of this array. 5. Use a (you have to use a) to display...
In a random sample of 100 college students, scores on a test were normally distributed with...
In a random sample of 100 college students, scores on a test were normally distributed with a mean of 80 points and standard deviation of 12 points. Use this scenario to answer the following questions: A. In this scenario, what is the point estimate? [2 points] B. Construct a 95% confidence interval to estimate the mean score in the population of all college students. Remember to show all work. Round your final answer to 3 decimal places. [4 points] C....
Write a java code segment to declare an array of size 10 of type String and...
Write a java code segment to declare an array of size 10 of type String and read data for them from a file, prompt user for the file name. Data is stored in a file with 1 string per line.
1.Declare a two-dimensional array of Strings namedchessboard.
1. Declare a two-dimensional array of Strings named chessboard.2. Declare a two-dimensional array of integers named tictactoe.3. Declare and create a two-dimensional array of chars,tictactoe, with 3 rows, each with 3 elements.4. Create a two-dimensional array of ints, plan, with 2 rows, and and 3 columns and initialize the first row to 8, 20, 50 and the second row to 12, 30, 75. Use member initializer syntax.
C++ please 1. Randomly assign integers in the range of 1-100 to a two-dimensional array. Write...
C++ please 1. Randomly assign integers in the range of 1-100 to a two-dimensional array. Write a program that finds the average value of the rows and the average value of the columns. Display the averages. 2. Create an array of randomly generated numbers in any range. Write a function that takes the array as an argument and returns an array that consists of only the even numbers in the original array. Use the function in a program. 3. Create...
Instructions Write a Java program that asks the user t enter five test scores. The program...
Instructions Write a Java program that asks the user t enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: * calcAverage -- This method should accept five test scores as arguments and return the average of the scores. * determineGrade -- This method should accept a test score as an argument and return a letter grade for the score, based on the following...
The following data set represents the test scores of the freshmen on the first in a...
The following data set represents the test scores of the freshmen on the first in a statistics course at a local university. 62 67 74 48 100 93 49 57 77 63 82 10 78 88 99 44 51 80 71 39 58 76 89 94 70 41 66 82 18 73 a. Calculate the z-score for the observation 63 and interpret it. b. Find the median of the data set. If the z-score for an observation is -1.22, the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT