Question: Hello, I have a question regarding my get function as it doesen't seem to be working, thanks! package matrix; import java.util.List; import java.util.ArrayList; /** *

Hello, I have a question regarding my get function as it doesen't seem to be working, thanks!

package matrix;

import java.util.List; import java.util.ArrayList;

/** * This class provides a data representation for the AbstractMatrix * implementation of the Matrix API. * It uses a list of list of integers to store matrix elements. */ public class ArrayListImplementation extends AbstractMatrix {

/** * Creates a list representation of a matrix of integers. * Elements of the list are initialized to zero. * @param numRows the number of rows in the matrix * @param numColumns the number of columns in the matrix * @throws MatrixException if dimensions are not positive */ public ArrayListImplementation(int numRows, int numColumns) { // You must provide super.setNumRows(numRows); super.setNumColumns(numColumns); elements = new ArrayList<>(numRows); for (int i=0; i < numRows; i++) { elements.add(new ArrayList(numColumns)); } super.clear(); } /** * Gets the element at the indicated row and column in this matrix. * * @param row the row position for the element. * @param column the column position for the element. * @return the element at the indicated row and column * @throws MatrixException if row or column is out of range */ @Override public int get(int row, int column) { checkBounds(row, column); // simple helper method for throwing the exception, this part is correct return elements.get(row).get(column); // this is the part I am confused on. } // Private instance fields go here private List> elements; }

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!