Up to this point you have been instructed to • Submit both the .java and .class
ID: 3774003 • Letter: U
Question
Up to this point you have been instructed to
• Submit both the .java and .class files when you submit an assignment, and to
• Provide method-level javadoc
This homework will illustrate the importance of these two items when working in a team.
I have written a file called Matrix.java that is approximately 430 lines of code including inline comments and Javadoc comments.
Your task is to write the driver that tests the contents of my Matrix class. I have provided the .class file and an archive of the javadoc for you to use when completing this assignment, but not the .java file. Your only knowledge about the contents of the Matrix class comes from the supplied Javadoc.
Impact
In the future you will be expected to submit your Javadoc (a compressed folder) alongside the .java and .class files when you submit an assignment.
Specifications Setup - class file and javadoc
For this to work you will need to follow these directions:
1. Download the files from the dropbox website
• Matrix.class
• doc.zip
And save them to a folder called HW07-MatrixDriver
2. You must uncompress (extract) the doc.zip file. This should create a folder called doc. If you go into this subfolder and double-click on Matrix.html you will open up the javadoc for the Matrix class.
3. You must create your new file called MatrixDriver.java in the HW07-MatrixDriver directory (the same place where the Matrix.class file is)
The Driver
You will write one file called MatrixDriver.java it will have exactly one method public static void main (String[ ] args). Your task is to test every method that appears in the Javadoc.
Example Output
Example Output Cont.
Notes/Hints
Take your time to map out how (the order) you should go about testing the methods that appear in the Javadoc. I advise printing out the Javadoc so that you have it beside you when you are developing your testing roadmap.
If you are trying to replicate my example output verbatim (word-for-word) remember what the word random means. It is highly unlikely that you will be able to replicate the output, but it serves as a coarse example.
Matrix D Testing Constructor that take double integer array as a parameter 00 00 3.00 4,00 5,00 6.00 1.00 9.00 3.00 Matrix A Testing named Constructor random which takes two parameters (row, col) and return a "new" Matrix 00 1,00 00 2.00 2.00 4.00 7.00 5.00 3.00 4.00 10,00 2,00 0.00 3.00 10.00 2.00 10.00 9.00 5.00 3,00 00 0.00 3.00 Testing the swap rows method Matrix A 00 1.00 00 2.00 2.00 4.00 10.00 2.00 3.00 4.00 7,00 5,00 0.00 3.00 10.00 10.00 2.00 9.00 5.00 3,00 00 0.00 3.00 Testing the transpose mact hod on Matrix H Matrix A 00 ,00 00 10,00 5.00 10.00 00 7.00 3.00 4.00 10.00 00 3.00 00 2,00 0,00 0,00 7,00 0.00 3.00 2.00 3.00 3.00 which takes a single parameter (i) and returns Matrix C Testing named Constructor d entity "new" (i x I) identity Matrix 00 0,00 0,00 0.00 0.00 0.00 1.00 0.00 0.00 0,00 0.00 1,00 0.00 0.00 0.00 0.00 0.00 0.00 0,00 0,00 0,00 0.00 1.00 Matrix E resting Mint fix Addition 5,00 8,00 2,00 12.00 7.00 20.00 6.00 5.00 9.00 8,00 9.00 10,00 10.00 7.00 12.00 10.00 2.00 00 7,00 6.00 7.00 9.00 6.00 Matrix F Testing Matrix Subtraction (A B) 0,00 3.00 0,00 8.00 3,00 3.00 5.00 2.00 0.00 0.00 0,00 5.00 0,00 10.00 1,00 8.00 2.00 10.00 9.00 3,00 0,00 1,00 9.00 0.00 Matrix C Mntrix scalar tiplication (c Testing 1, 20 1,20 80 2.40 2.40 3.60 12.00 2.40 4,80 6,00 0.00 3.60 10.80 12.00 12.00 8.40 3.60 6.00 80 0.00 3.60 Matrix AB Testing Matrix Multiplication (A x B) 28.00 37.00 H0.00 26.00 120.00 105,00 107.00 28,00 87.00 105.00 131.00 37.00 99.00 70.00 131.00 334,00 84.00 107,00 123,00 30.00 67.00 9.00 70.00 123.00Explanation / Answer
import java.util.*;
public class MatrixDriver{
public static void main(String args[]){
//reading matrix from user
Scanner sc = new Scanner(System.in);
System.out.println("Enter matrix length: ");
int n = sc.nextInt();
double[][] mat = new double[n][n];
//raeding elements
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
mat[i][j] = sc.nextInt();
}
}
//creaing matrix object first
Matrix obj = new Matrix(mat,5,5);
//testing constructor matrix
double[][] A = obj.construct(5,5);
System.out.println("Testing matrix constructor");
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
System.out.print(A[i][j]);
}
System.out.println();
}
//testing swap rows
System.out.println("Testing matrix swapping");
double[][] temp1 = obj.swap(A);
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
System.out.print(temp1[i][j]);
}
System.out.println();
}
//testing transpose rows
System.out.println("Testing matrix transpose");
temp1 = obj.transpose(A);
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
System.out.print(temp1[i][j]);
}
System.out.println();
}
//testing constructor matrix with single parameter
double[][] B = obj.construct(5);
System.out.println("Testing matrix constructor with single parameter");
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
System.out.print(B[i][j]);
}
System.out.println();
}
//testing addition
System.out.println("Testing matrix addition");
temp1 = obj.add(A,B);
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
System.out.print(temp1[i][j]);
}
System.out.println();
}
//testing subtraction
System.out.println("Testing matrix subtraction");
temp1 = obj.sub(A,B);
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
System.out.print(temp1[i][j]);
}
System.out.println();
}
//testing scalar multiplication
System.out.println("Testing matrix scalar multiplication");
temp1 = obj.scalar(A,B);
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
System.out.print(temp1[i][j]);
}
System.out.println();
}
//testing matrix multiplication
System.out.println("Testing matrix multiplication AXB");
temp1 = obj.mult(A,B);
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
System.out.print(temp1[i][j]);
}
System.out.println();
}
//testing matrix multiplication
System.out.println("Testing matrix multiplication BXA");
temp1 = obj.mult(B,A);
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
System.out.print(temp1[i][j]);
}
System.out.println();
}
//testing matrix multiplication
System.out.println("Testing matrix equality AXB");
boolean res = obj.equal(A,A);
System.out.println("Result: "+res);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.