Programming and Problem Solving with Java

(やまだぃちぅ) #1

CASE STUDY^613


// Creates empty matrix
{
matrix = new double[rows][columns];
}

publicMatrix(double[][] data)
// Stores the reference argument into matrix
{
matrix = data;
}

public doubleknowValueAt(introw, intcol)
// Returns the value at matrix[row][col]
{
returnmatrix[row][col];
}

public intknowRows()
// Returns the number of rows in matrix
{
returnmatrix.length;
}

public intknowColumns()
// Returns the number of columns in matrix
{
returnmatrix[ 0 ].length;
}

public voidsetValue(doubledataItem, introw, intcol)
// Sets matrix[row][col] to dataItem
{
matrix[row][col] = dataItem;
}

public voidprintMatrix(PrintWriter outFile)
// Writes matrix on outFile by row
{
for(introw = 0 ; row < matrix.length; row++)
{
for(intcol = 0 ; col < matrix[ 0 ].length; col++)
outFile.print(matrix[row][col] + " ");
outFile.println();
outFile.println();
}
}
Free download pdf