You are to write a program that reads an input file containing two matrices, and that repeatedly asks the user if they want to print, add, subtract, transpose, or quit. Here is a sample run of the program: See image.
A sample input file, matrix.txt, Here are the contents of matrix.txt:
3 5
8 19 7 15 4
21 42 9 0 26
13 7 2 1 16
3 5
2 12 6 9 0
40 22 8 4 17
3 13 8 29 10
You may assume that any input file has the same format:
Note that the two matrices do NOT have to have the same dimensions.
Your program should have two classes, Matrix and Proj4.
Matrix should be a general class that represents a matrix. It should have instance variables for the number of rows, number of columns, and a two-dimensional array of the matrix values. It should also have a constructor that takes the number of rows and columns as parameters, initializes the instances variables, and allocates space for the twodimensional array. It should also have the following methods:
The setElem method should update the two-dimensional array to put that value at the specified row/column position. The toString method should return a string representation of this Matrix so that if that string was printed, it would print in the format shown in the screenshot above. The plus method should return a new Matrix object that is THIS Matrix plus m (the minus method should be similar, but with a different operation). The transpose method should return a new Matrix object that is the transposition of THIS Matrix.
The Proj4 class should contain a single main method. It should first open the matrix file specified as a command-line argument. It should then create two Matrix objects and fill them with values using setElem. Then, it should repeatedly ask the user for an option and call the appropriate method (toString, plus, minus, or transpose), and print the results.
Here are some additional requirements and tips:
You should put a description of the project at the top of the file and at the top of each method. Please use this template for the top of the file:
/**
* (description of the project)
*
* @author (your name)
* @version (which number project this is)
*/
Please use this template for the top of each method:
/**
* (description of the method)
*
* @param (describe first parameter)
* @param (describe second parameter)
* (list all parameters, one per line)
* @return (describe what is being returned)
*/