Question: The section from the previous homework is provided below: import java.util.Scanner; public class Matrix{ public static void main(String[] args) { Scanner input = new Scanner(System.in)

![public class Matrix{ public static void main(String[] args) { Scanner input =](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f12e5713fc3_07066f12e567b015.jpg)


The section from the previous homework is provided below:
import java.util.Scanner;
public class Matrix{
public static void main(String[] args) {
Scanner input = new Scanner(System.in) ;
int row, col ;
while (true) {
System.out.print("Enter the number of rows (MAX:5): ");
row = input.nextInt() ;
if (row > 0 && row
break;
}
System.out.print("Invalid row size. Try again (MAX:5");
}
while(true) {
System.out.print("Enter Number of columns (MAX:5): ");
col = input.nextInt();
if (col > 0 && col
break;
}
System.out.print("Invalid column size. Try again (MAX:5");
}
int[][] matrix = new int[row][col] ;
int startVal = 0;
for (int i = 0; i
for (int j = 0; j
matrix [i][j] = (i * 10) + startVal + j ;
}
}
printMatrix(matrix) ;
char choice;
do {
System.out.println(" T transpose") ;
System.out.println("C columnSum") ;
System.out.println("r reverseRows") ;
System.out.println("Q quit") ;
System.out.print("Your choice: ") ;
choice = input.next().toLowerCase().charAt(0) ;
switch(choice) {
case 't': transpose(matrix) ;
break ;
case 'c': columnSum(matrix) ;
break ;
case 'r': reverseRows(matrix) ;
break ;
case 'q':
System.exit(0);
default: System.out.println("Invalid choice, try again") ;
}
}while(choice != 'q');
}
public static void printMatrix(int[][] matrix) {
// method to print matrix
int row = matrix.length ;
int col = matrix[0].length ;
for (int i = 0; i
for (int j = 0; j
System.out.printf("%3d", matrix[i][j]) ;
}
System.out.println();
}
}
public static void transpose(int[][] matrix) {
// method for changing rows to columns and vice versa
int row = matrix.length ;
int col = matrix[0].length ;
int[][] new_mat = new int[col][row];
for (int i = 0; i
for (int j = 0; j
new_mat[j][i] = matrix[i][j] ;
}
}
printMatrix(new_mat);
}
public static void columnSum(int[][] matrix) {
// method to calculate the sum of values in each column
int row = matrix.length ;
int col = matrix[0].length ;
for (int i = 0; i
int sum = 0;
for (int j = 0; j
sum += matrix[j][i] ;
}
System.out.printf("%3d", sum);
}
System.out.println();
}
public static void reverseRows(int[][] matrix) {
// method to reverse the elements in every row of Matrix
int row = matrix.length ;
int col = matrix[0].length ;
int [][] new_mat = new int[row][col] ;
for (int i = 0; i
for (int j = 0; j
new_mat[i][j] = matrix[i][col - j - 1];
}
}
printMatrix(new_mat);
}
}
I need help with making the class, object, modifications to the methods and Part C. Please help!!!
CS101 Homework 15: Matrix Object Operations In this assignment, you will re-use code that you wrote in the previous Matrix assignment, but you will re-organize the code into a Matrix class, create a Matrix object, and then operate on that matrix object. The Transpose, Reverse, SumColumns, matrix values initialization, matrix printing code, user row and column input, and menu that you wrote in the previous Matrix homework assignment can be leveraged in this assignment. A. Program Description (the description for A. below matches the previous assignment) Your program should do the following 1. Prompt the user for the number of rows and the number of columns in the matrix. The maximum number of rows or columns is 5, the minimum is 1. Your program will ask the user what size matrix to create and you should trap illegal size requests 2. Generate a matrix having the dimensions specified by the user 3. Assign integers to each element of the matrix as follows (first row starts with 0, increment by one for each column; second row starts with 10, increment by one for each column;...): If the user enters 3 rows and 2 columns, the matrix is initialized with exactly the following values 1 10 20 21 If the user enters 4 rows and 5 columns, the matrix is initialized with exactly these values 1 10 20 2 12 3 13 23 14 24 21 30 31 32 33 34 4. Your program should print the matrix to the screen. 5. After displaying the matrix, display a menu to the user with the following options - Rows become columns (and vice versa) - Calculate the sum of the values in each column T transpose C columnSum R reverseRows- Reverse all elements in every row of the matrix 2 quit - Exit the program The program should accept case insensitive input e.g. both Q and q will cause the program to be exited 6. If the user selects one of the first three options, the operation should be applied to the original matrix of numbers and either the new matrix should be displayed or the results computed by the operation should be shown, as applicable Each time a menu option is selected, the appropriate method should use the original matrix as its input - it should only read values from the original matrix - it should never write to the original matrix. 7. After the result is displayed, the menu with the above choices should be shown again 2017,2018 Suzanne Mclntosh CS101 Homework 15: Matrix Object Operations In this assignment, you will re-use code that you wrote in the previous Matrix assignment, but you will re-organize the code into a Matrix class, create a Matrix object, and then operate on that matrix object. The Transpose, Reverse, SumColumns, matrix values initialization, matrix printing code, user row and column input, and menu that you wrote in the previous Matrix homework assignment can be leveraged in this assignment. A. Program Description (the description for A. below matches the previous assignment) Your program should do the following 1. Prompt the user for the number of rows and the number of columns in the matrix. The maximum number of rows or columns is 5, the minimum is 1. Your program will ask the user what size matrix to create and you should trap illegal size requests 2. Generate a matrix having the dimensions specified by the user 3. Assign integers to each element of the matrix as follows (first row starts with 0, increment by one for each column; second row starts with 10, increment by one for each column;...): If the user enters 3 rows and 2 columns, the matrix is initialized with exactly the following values 1 10 20 21 If the user enters 4 rows and 5 columns, the matrix is initialized with exactly these values 1 10 20 2 12 3 13 23 14 24 21 30 31 32 33 34 4. Your program should print the matrix to the screen. 5. After displaying the matrix, display a menu to the user with the following options - Rows become columns (and vice versa) - Calculate the sum of the values in each column T transpose C columnSum R reverseRows- Reverse all elements in every row of the matrix 2 quit - Exit the program The program should accept case insensitive input e.g. both Q and q will cause the program to be exited 6. If the user selects one of the first three options, the operation should be applied to the original matrix of numbers and either the new matrix should be displayed or the results computed by the operation should be shown, as applicable Each time a menu option is selected, the appropriate method should use the original matrix as its input - it should only read values from the original matrix - it should never write to the original matrix. 7. After the result is displayed, the menu with the above choices should be shown again 2017,2018 Suzanne Mclntosh
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
