All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class structure.Matrix

java.lang.Object
    |
    +----structure.Matrix

public class Matrix
extends Object
An implementation of rectangular vectors. This implementation of a Matrix is minimal. Few operations are provided, and no support for mathematical operations is considered.


Constructor Index

 o Matrix()
Construct an empty matrix.
 o Matrix(int, int)
Constructs a matrix such that all values are null.

Method Index

 o elementAt(int, int)
Fetch an element from the matrix.
 o height()
Return the height of the matrix.
 o insertColAt(int)
Add a new column, whose index will be c.
 o insertRowAt(int)
Add a new row, whose index will be r.
 o removeColAt(int)
Remove a column, whose index is c.
 o removeRowAt(int)
Remove the row whose index is r.
 o setElementAt(Object, int, int)
Change the value at location (row, col)
Precondition:
0 <= row < height(), 0 <= col < width()
Postcondition:
changes location (row,col) to value
 o toString()
Construct a string representation of the matrix.
 o width()
Return the width of the matrix.

Constructors

 o Matrix
public Matrix()
Construct an empty matrix.

Postcondition:
constructs empty matrix

 o 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.

Methods

 o 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
Returns:
Object located at matrix position (row,col)
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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