Lab 04

Matrix Addition

 

Objective:

 

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

Lab Solution

 

Requirements:

 

Example Dialog:

*The following Example Dialog demonstrates the interactions between a user and ONE possible implementation of the required software’s front-end / user interface. The software’s front-end / user interface may be implemented in MANY different ways and will receive full credit as long as it meets the most minimal of the above requirements. While you may use the example dialog as a guide, it is strongly encouraged to create the front-end / user interface in your own way. *

Key

Unhighlighted Text

Program’s Output

Highlighted Text

User’s Input

 

Welcome to the matrix adder 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

=

5 4

10 11

 

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

=

5 4

10 11

  1. If the user creates the following matrices

Does the program output

1 2

3 4

+

5 6

7 8

=

6 8

10 12

  1. If the user creates the following matrices

Does the program output

Invalid Dimensions. These cannot be added.

 

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: