Question: *Java Part A Create a package called matrix and inside that package: Create a class called Matrix that encapsulates a multiplication table. The class must

*Java

Part A

  • Create a package called matrix and inside that package:
    • Create a class called Matrix that encapsulates a multiplication table. The class must include:
      • Private instance variable for a 2D array of integers
      • Do not have any other instance variables
      • A constructor that
        • Has two arguments, the number of rows and columns to define the matrix
        • Instantiates the 2D array using the rows and columns
        • Calls the private method to fill the array with values (see below)
      • A public accessor that will return the array
      • A public mutator that
        • Has two arguments, the new number of rows and columns
        • Instantiates a new array using the number of rows and columns passed in
        • Calls the private method to fill the array
      • A private method that will fill the array with values to form a multiplication table
        • It must use nested loops to fill the array
        • The value in each element is the row number times the column number
        • Do not hardcode any values in the array
        • Do not hardcode the array size use the array length
      • A public method that will
        • Instantiate an array list to hold all the values in the matrix
        • It must flatten the 2D array by row
        • Return the array list object
        • For example, suppose you have a 3 x 3 matrix

0 0 0

0 1 2

0 2 4

It would flatten to 0, 0, 0, 0, 1, 2, 0 2, 4 in the array list

  • A public method to print the multiplication table
    • Print the table, using printf and nested loops, with all the values aligned
    • The width, i.e., the number of digits reserved for the number, is based on the largest number. There is one space between each column.
    • The first row has the column header values
    • The first column has the row header values
    • For example, the largest number is two digits, so we reserve two and a space

0 1 2 3 4 5

0 0 0 0 0 0 0

1 0 1 2 3 4 5

2 0 2 4 6 8 10

3 0 3 6 9 12 15

4 0 4 8 12 16 20

5 0 5 10 15 20 25

I'm mostly confused on how the parts in bold. The code I have now is down below, please explain how you got your answers.

*Java Part A Create a package called matrix and inside that package:

package matrix; import java.util.Arrays; public class Matrix { private int[][] array2D; public Matrix(int num_row, int num_col) { for(int i = 0; i

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!