Question: JAVA Exercise : Build the Matrix2D class according the UML specifications below. While you can assume that the class will contain only integer valued matrices,

JAVA Exercise: Build the Matrix2D class according the UML specifications below. While you can assume that the class will contain only integer valued matrices, there is no requirement that such matrices be rectangular, or even square. Make sure your class handles ragged/jagged matrices!

 Matrix2D --------------------- table : int [ ] [ ] --------------------- + Matrix2D (entries : int [ ] [ ]) + getMaxEntry() : int + getMinEntry() : int + getAllColumnsTotals () : int [ ] + getAllRowsTotals () : int [ ] + getColumnTotal ( idx : int ) : int + getRowTotal ( idx : int ) : int + getMaxColumnNumber () : int + display : void + toString() : String + getFormat() : String Main method for testing: You can test your Matrix2D class using the following main() method public class Matrix2DTest { public static void main(String[] args) { // Comment out/Uncomment the proper line for 4 different test runs Matrix2D table = new Matrix2D(new int[]{1, 2, 5}, new int[]{55, 6}, new int[]{7, -83, 9, 10}); // RUN #1 //Matrix2D table = new Matrix2D(new int[]{1}); // RUN #2 //Matrix2D table = new Matrix2D(new int[] {7, -83, 9, 10}); // RUN #3 //Matrix2D table = new Matrix2D(new int[]{1, -2, 5}, new int[]{5, 6, 17}, new int[] {7, 83, -9}); // RUN #4 System.out.println(" === Showing the display method ==="); System.out.println("Format is " + table.getFormat()); System.out.println("------------------"); table.display(); System.out.println("=== Getting max & min ==="); System.out.println("Max = " + table.getMaxEntry()); System.out.println("Min = " + table.getMinEntry()); System.out.println(" === Getting row/columns totals vectors ==="); System.out.println("Row totals: " + Arrays.toString(table.getAllRowsTotals())); System.out.println("Column totals: " + Arrays.toString(table.getAllColumnsTotals())); System.out.println(" === Testing individual row/columns totals ==="); System.out.println("Total row 1: " + table.getRowTotal(1)); System.out.println("Total column 4: " + table.getColumnTotal(4)); System.out.println("Total column -1: " + table.getColumnTotal(-1)); System.out.println(" === Testing toString() ==="); System.out.println(table); } } 

Sample output for the first uncommented line:

=== Showing the display method ===

Format is %3d

------------------

1 2 5

55 6

7 -83 9 10

=== Getting max & min ===

Max = 55

Min = -83

=== Getting row/columns totals vectors ===

Row totals: [8, 61, -57]

Column totals: [63, -75, 14, 10]

=== Testing individual row/columns totals ===

Total row 1: 61

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!