## structure5 Class Matrix<E>

```java.lang.Object
structure5.Matrix<E>
```

`public class Matrix<E>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.

Example Usage:

``` public static void main(String[] argv){
//create an array of arrays to bet copied into the matrix
int[][] test = new int[][]{new int[]{1,2,3},
new int[]{4,5,6},
new int[]{7,8,9}};

//create the matrix
Matrix testMatrix = new `Matrix(test.length, test[0].length)`;

//copy the 2-d array into the matrix
for(int i = 0; i < test.length; i++){
for(int j = 0; j < test[0].length; j++){
testMatrix.`set(i,j,new Integer(test[i][j]))`;
}
}

//print out the matrix
System.out.println(testMatrix);
}
```

Constructor Summary
`Matrix()`
Construct an empty matrix.
```Matrix(int h, int w)```
Constructs a matrix such that all values are null.

Method Summary
` void` `addCol(int c)`
Add a new column, whose index will be c.
` void` `addRow(int r)`
Add a new row, whose index will be r.
` E` ```get(int row, int col)```
Fetch an element from the matrix.
` int` `height()`
Return the height of the matrix.
` Vector<E>` `removeCol(int c)`
Remove a column, whose index is c.
` Vector<E>` `removeRow(int r)`
Remove the row whose index is r.
` void` ```set(int row, int col, E value)```
Change the value at location (row, col)
` String` `toString()`
Construct a string representation of the matrix.
` int` `width()`
Return the width of the matrix.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Matrix

`public Matrix()`
Construct an empty matrix.

### Matrix

```public Matrix(int h,
int w)```
Constructs a matrix such that all values are null.

Parameters:
`h` - Height of the matrix.
`w` - Width of the matrix.
Method Detail

### get

```public E get(int row,
int col)```
Fetch an element from the matrix.

Parameters:
`row` - The row of the element
`col` - The column of the element
Returns:
Object located at matrix position (row, col)

### set

```public void set(int row,
int col,
E value)```
Change the value at location (row, col)

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.

`public void addRow(int r)`
Add a new row, whose index will be r.

Parameters:
`r` - The index of the newly inserted row.

`public void addCol(int c)`
Add a new column, whose index will be c.

Parameters:
`c` - The index of the newly inserted column.

### removeRow

`public Vector<E> removeRow(int r)`
Remove the row whose index is r. The row is returned as a vector.

Parameters:
`r` - The index of the to-be-removed row.
Returns:
A vector of values once in the row.

### removeCol

`public Vector<E> removeCol(int c)`
Remove a column, whose index is c.

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.

Returns:
The number of columns in the matrix.

### height

`public int height()`
Return the height of the matrix.

Returns:
The number of rows in the matrix.

### toString

`public String toString()`
Construct a string representation of the matrix.

Overrides:
`toString` in class `Object`
Returns:
A string, representing the matrix.