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) None
Know value at (row, col) None
return double
Know number of rows None
return int
Know number of columns
return Matrix
None
return int
Subtract (two) from self None
return Matrix
Multiply self times (two) None
return Matrix
Print (outFile) PrintWriter
Add self to (two) None
Set a value at (row, col, value) None