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....
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.
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.
This program needs to be in Java Exercise on Single Dimensional Arrays Declare an array reference...
This program needs to be in Java Exercise on Single Dimensional Arrays Declare an array reference variable arrayInt for an array of integers. Create the array of size 100, and assign it to arrayInt. (2 points) Write a method to populate the array with Random numbers between 1 to 25. Signature of the method is: populateArray( int[] ) which returns nothing. Call this method from main with arrayInt--> populateArray(arrayInt). (2 points) Write a method to print an array. Signature of...
Two groups of students are selected to test different learning techniques. The test scores of group...
Two groups of students are selected to test different learning techniques. The test scores of group 1 were: 95, 73, 68, 95, 98, 79, 98, 86, 76, 89, 89, 94. The test scores of group 2 were: 100, 80, 95, 90, 95, 98, 100, 100. Can it be said with 95% confidence that one group outperformed the other?
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT