Question: JAVA Matrix OOP ( Change my single class code to OOP): I did above and wrote this code: import java.util.Scanner; public class Matrix { public
JAVA Matrix OOP ( Change my single class code to OOP):

I did above and wrote this code:
import java.util.Scanner; public class Matrix { public static void main(String[] args){ Scanner in = new Scanner(System.in); int row, col; while(true){ System.out.print("Enter number of rows: "); row = in.nextInt(); if(row>0 && rowbreak; System.out.println("Invalid row size! Try again"); } while(true){ System.out.print("Enter number of columns: "); col = in.nextInt(); if(col>0 && colbreak; System.out.println("Invalid column size! Try again"); } int[][] matrix = new int[row][col]; // System.out.print("Enter start value:"); int startVal = 0; for(int i=0;ifor(int j=0; j 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 = in.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! "); } }while(choice!='q'); } public static void printMatrix(int[][] matrix){ int row = matrix.length; int col = matrix[0].length; for(int i=0; ifor(int j=0;j "%3d",matrix[i][j]); } System.out.println(); } } public static void transpose(int[][] matrix){ int row = matrix.length; int col = matrix[0].length; int[][] new_mat = new int[col][row]; for(int i=0; ifor(int j=0;j public static void columnSum(int[][] matrix){ int row = matrix.length; int col = matrix[0].length; for(int i=0; i int sum = 0; for(int j=0;j"%3d", sum); } System.out.println(); } public static void reverseRows(int[][] matrix){ int row = matrix.length; int col = matrix[0].length; int[][] new_mat = new int[row][col]; for(int i=0; ifor(int j=0;j
Now I am asked to do the following: Please help me with code for doing what is below with the code I wrote above:

![public static void main(String[] args){ Scanner in = new Scanner(System.in); int row,](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3d9fd70783_08466f3d9fce04b0.jpg)


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: 10 20 21 If the user enters 4 rows and 5 columns, the matrix is initialized with exactly these values: 10 11 12 13 14 20 21 22 23 24 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 revereos 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
