Lab 04

Matrix Subtraction

 

Objective:

 

Write a program that creates two matrices of whole numbers and then subtracts them!

Lab Solution

 

Requirements:

 

Example Dialog:

 

Welcome to the matrix subtractor program!

Please enter the length and width of the first matrix

2

2

Enter value at index 0 0

4

Enter value at index 0 1

1

Enter value at index 1 0

8

Enter value at index 1 1

7

 

Please enter the length and width of the second matrix

2

2

Enter value at index 0 0

1

Enter value at index 0 1

3

Enter value at index 1 0

2

Enter value at index 1 1

4

 

4 1

8 7

-

1 3

2 4

=

3 -2

6 3

 

Solution Tests:

  1. Is your name written as a comment in all source files?
  2. Does the solution compile (no syntax errors)?
  3. If the user creates the following matrices

Does the program output

4 1

8 7

-

1 3

2 4

=

3 -2

6 3

  1. If the user creates the following matrices

Does the program output

1 2

3 4

-

5 6

7 8

=

-4 -4

-4 -4

  1. If the user creates the following matrices

Does the program output

Invalid Dimensions. These cannot be subtracted.

 

Lab Report

  1. Create a section named “Problem” and describe this lab’s problem in your own words. (10pts).
  2. Create a section named “Solution Description” and describe how the code solves the problem in your own words. (10pts).
  3. Create a section named “Problems Encountered” and describe the various syntax, run-time, and logic errors that were encountered while implementing the solution. (10pts).
  4. Draw a flow chart of the solution and include that in the proposed solution section
  5. Is it possible to have “ragged” / “jagged” arrays in Java?
  6. Given the following code snippet, are there any kind of errors? If so, name the types, where, and how this code can be fixed. Otherwise, what does this code exactly print to the console?

 

 

  1. Given the following code snippet, are there any kind of errors? If so, name the types, where, and how this code can be fixed. Otherwise, what does this code exactly print to the console?

 

 

  1. Given the following code snippet, are there any kind of errors? If so, name the types, where, and how this code can be fixed. Otherwise, what does this code exactly print to the console?

 

 

  1. Given the following code snippet, are there any kind of errors? If so, name the types, where, and how this code can be fixed. Otherwise, what does this code exactly print to the console?

 

 

  1. Given the following code snippet, are there any kind of errors? If so, name the types, where, and how this code can be fixed. Otherwise, what does this code exactly print to the console?

 

Finally:

Upload the source code (.JAVA File Extension) and written lab report (.DOC, .DOCX, or .PDF file extension) to the CSCE Dropbox.