package chapter9; /** * Title: Chapter 9, "Object-Oriented Software Development" * Description: Examples for Chapter 9 * Copyright: Copyright (c) 2000 * Company: Armstrong Atlantic State University * @author Y. Daniel Liang * @version 1.0 */ // GenericMatrix.java: Define a matrix and its associated // operations such as add and multiply public abstract class GenericMatrix { // Representation of a matrix using a two-dimensional array private Object[][] matrix; /**Construct a matrix*/ protected GenericMatrix(Object[][] matrix) { this.matrix = matrix; } /**Return matrix*/ public Object[][] getMatrix() { return matrix; } /**Set a new matrix*/ public void setMatrix(Object[][] matrix) { this.matrix = matrix; } public abstract GenericMatrix createGenericMatrix(); /**Add two matrices*/ public GenericMatrix addMatrix(GenericMatrix secondGenericMatrix) { // Create a result matrix Object[][] result = new Object[matrix.length][matrix[0].length]; // Obtain the second matrix Object[][] secondMatrix = secondGenericMatrix.getMatrix(); // Check bounds of the two matrices if ((matrix.length != secondMatrix.length) || (matrix[0].length != secondMatrix.length)) { System.out.println( "The matrices do not have the same size"); System.exit(0); } // Perform addition for (int i=0; i