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 C++ Declare an integer array of size 20 and assign the array with 20 randomly...
In C++ Declare an integer array of size 20 and assign the array with 20 randomly generated integers in the range [1, 100]. Shuffle the data in the array so that all numbers smaller than 50 are put before the numbers greater or equal to 50. Note you are not allowed to create any other arrays in the program. Finally, print out the shuffled array. (25 points) #include<iostream> using namespace std; const int NUM = 20; int main() {      ...
Declare an integer array of size 20 and assign the array with 20 randomly generated integers...
Declare an integer array of size 20 and assign the array with 20 randomly generated integers in the range [1, 100]. Shuffle the data in the array so that all numbers smaller than 50 are put before the numbers greater or equal to 50. Note you are not allowed to create any other arrays in the program. Finally, print out the shuffled array. (25 points) #include<iostream> using namespace std; const int NUM = 20; int main() {             //...
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.
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?
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT