CASE STUDY^607
Internal Data Representation:Earlier, we said that an array is the ideal implementation
structure for a matrix. In many languages, we would have to include the number of
rows and number of columns as data fields in the Matrixclass. Java, however, provides
them automatically as instance variables in the array object. Let’s represent the
numeric values in the matrices as double; this strategy allows us to handle the largest
range of values.
public classMatrix
{
// Private data field
private double[][] matrix;
...
}
Class Name: Matrix Superclass: Object Subclasses:
Responsibilities Collaborations
Create itself (rows, columns) NoneKnow value at (row, col) None
return double
Know number of rows None
return intKnow number of columns
return Matrix
None
return intSubtract (two) from self None
return Matrix
Multiply self times (two) None
return MatrixPrint (outFile) PrintWriter
Add self to (two) NoneSet a value at (row, col, value) None