CASE STUDY
616
Shown below is a test driver that carries out the addition, subtraction, and
multiplication operations.
//***************************************************************
// Class MatrixDriver is a test driver for class Matrix. The four
// matrices that are defined are those used in the Background
// section of the Case Study. The same operations are performed.
// One additional operation is performed: An illegal multiply
// operation is requested and an exception is thrown.
//***************************************************************
importmatrix.*;
importjava.io.*;
public classMatrixDriver
{
public static voidmain(String[] args) throwsIOException
{
PrintWriter outFile;
outFile = newPrintWriter(newFileWriter("Matrix.out"));
Matrix result;
introw, col;
// Set up arrays and instantiate four objects of class Matrix
double[][] data1 =
{{5.0, 0.0, 1.0, 4.0},
{2.0, 1.0, 3.0, 2.0},
{1.0, 1.0, 0.0, 0.0},
{1.0, 2.0, 3.0, 4.0},
{2.0, 3.0, 1.0, 0.0}};
double[][] data2 =
{{1.0, 1.0, 1.0, 2.0},
{2.0, 1.0, 0.0, 3.0},
{1.0, 2.0, 4.0, 1.0},
{0.0, 0.0, 4.0, 5.0},
{0.0, 0.0, 1.0, 1.0}};
double[][] data3 =
{{1.0, 2.0, 3.0, 4.0},
{0.0, 2.0, 1.0, 3.0},
{1.0, 1.0, 0.0, 0.0}};
double[][] data4 =
{{1.0, 1.0},
{0.0, 1.0},
{2.0, 3.0},
{4.0, 2.0}};