Construct an empty matrix.
- Postcondition:
- constructs empty matrix
Matrix
public Matrix(int h,
int w)
- Constructs a matrix such that all values are null.
- Precondition:
- h >= 0, w >= 0;
- Postcondition:
- constructs an h row by w column matrix
- Parameters:
- h - Height of the matrix.
- w - Width of the matrix.
elementAt
public Object elementAt(int row,
int col)
- Fetch an element from the matrix.
- Precondition:
- 0 <= row < height(), 0 <= col < width()
- Postcondition:
- returns object at (row, col)
- Parameters:
- row - The row of the element
- col - The column of the element
setElementAt
public void setElementAt(Object value,
int row,
int col)
- Change the value at location (row, col)
- Precondition:
- 0 <= row < height(), 0 <= col < width()
- Postcondition:
- changes location (row,col) to value
- Parameters:
- value - The new Object reference (possibly null).
- row - The row of the value to be changed.
- col - The column of the value to be changed.
insertRowAt
public void insertRowAt(int r)
- Add a new row, whose index will be r.
- Precondition:
- 0 <= r <= height()
- Postcondition:
- inserts row of null values to be row r
- Parameters:
- r - The index of the newly inserted row.
insertColAt
public void insertColAt(int c)
- Add a new column, whose index will be c.
- Precondition:
- 0 <= c <= width()
- Postcondition:
- inserts column of null values to be column c
- Parameters:
- c - The index of the newly inserted column.
removeRowAt
public Vector removeRowAt(int r)
- Remove the row whose index is r.
The row is returned as a vector.
- Precondition:
- 0 <= r < height()
- Postcondition:
- removes row r and returns it as a Vector.
- Parameters:
- r - The index of the to-be-removed row.
- Returns:
- A vector of values once in the row.
removeColAt
public Vector removeColAt(int c)
- Remove a column, whose index is c.
- Precondition:
- 0 <= c < width
- Postcondition:
- removes column c and returns it as a vector
- Parameters:
- c - The index of the column to be removed.
- Returns:
- A vector of the values removed.
width
public int width()
- Return the width of the matrix.
- Postcondition:
- returns number of columns in matrix
- Returns:
- The number of columns in the matrix.
height
public int height()
- Return the height of the matrix.
- Postcondition:
- returns number of rows in matrix
- Returns:
- The number of rows in the matrix.
toString
public String toString()
- Construct a string representation of the matrix.
- Postcondition:
- returns string description of matrix.
- Returns:
- A string, representing the matrix.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index