CSE 1321L: Programming and Problem Solving I Lab Lab 13 Multi-Dimensional Arrays

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (5 votes)

Exercise #1: Develop a Java program (name it SumArrayColumns) that prints out the sum of each column of a two-dimensional array. The program defines method sumColumn() takes a two-dimensional array of integers and returns a single-dimensional array that stores the sum of columns of the passed array. The program main method prompts the user to enter a 3-by-4 array, prints out the array, and then calls method sumColumns(). Final, it prints out the array retuned by method sumColumns(). Document your code, and organize and space the outputs properly as shown below.

 

Sample run 1:

 

The entered matrix:

9    1    2    4

2    2    8    0

3    3    3    3

 

Sum of column 0 is 14

Sum of column 1 is 6

Sum of column 2 is 13

Sum of column 3 is 7

 

Sample run 2:

 

The entered matrix:

10   10   10   10

1    1    1    1

50   50   50   50

 

Sum of column 0 is 61

Sum of column 1 is 61

Sum of column 2 is 61

Sum of column 3 is 61

 

Sample run 3:

 

The entered matrix:

10   10   10   10

-10  -10  -10  -10

50   51   52   53

 

Sum of column 0 is 50

Sum of column 1 is 51

Sum of column 2 is 52

Sum of column 3 is 53

 

 

Exercise #2: Develop a program (name it LocateLargestElement) that prints out the location of the first largest value in a two-dimensional array. The largest values may appear more than once in the array. The program defines method locateLargest() that takes a two-dimensional array of integers and returns the location (row index and column index) of the first largest value as a single-dimensional array. The program main method prompts the user to enter a 3-by-4 matrix, prints out the matrix, and then calls method locateLargest(). Finally, it prints out the array retuned by method locateLargest(). Document your code, and organize and space the outputs properly as shown below.

 

Sample run 1:

 

The entered matrix:

9    1    2    4

2    11   18   20

3    20   3    12

 

First largest value is located at row 1 and column 3

 

Sample run 2:

 

The entered matrix:

19   11   22   44

29   51   81   20

23   90   45   90

 

First largest value is located at row 2 and column 1

 

Sample run 3:

 

The entered matrix:

89   11   22   44

29   51   80   20

33   10   45   10

 

First largest value is located at row 0 and column 0

 

 

Exercise #3: Develop a program (name it AddMatrices) that adds two matrices. The matrices must of the same size. The program defines method Addition() that takes two two-dimensional arrays of integers and returns their addition as a two-dimensional array. The program main method defines two 3-by-3 arrays of type integer. The method prompts the user to initialize the arrays. Then it calls method Addition(). Finally, it prints out the array retuned by method Addition(). Document your code, and organize and space the outputs properly as shown below.

 

Sample run 1:

 

Matrix A:

2    1    2

7    1    8

3    20   3

 

Matrix B:

1    1    1

1    1    1

1    1    1

 

A + B:

3    2    3

8    2    9

4    21   4

 

Sample run 2:

 

 

Matrix A:

2    2    2

2    2    2

2    2    2

 

Matrix B:

2    2    2

2    2    2

2    2    2

 

A + B:

4    4    4

4    4    4

4    4    4

 

 

Instructions:

 

  1. Programs must be working correctly.
  2. Programs must be completed and checked before working the assignment.
  3. Programs must be checked by the end of the designated lab session.