Question: /* * Author: * Date: * Program: Lab8Program.java * Demonstrate Two Dimensional Arrays. * Purpose: * You are required to write purpose of each method
/*
* Author:
* Date:
* Program: Lab8Program.java
* Demonstrate Two Dimensional Arrays.
* Purpose:
* You are required to write purpose of each method here
* populateMatrix:
* outputMatrix:
* findLocationOfLargest:
* getDiagonal:
* transpose:
* find:
* sortedRow:
* rowSum:
* matrixCopy:
*/
public class Lab8Program{
public static void main(String[] args){
//Instantiate a two dimensional array of type int with 3 rows and 3 columns, call it matrix.
//invoke populateMatrix method, pass matrix as argument.
System.out.println(" Matrix after populating");
//invoke outputMatrix method, pass matrix as argument.
/*invoke findLocationOfLargest method, pass matrix as argument. Store the returned array
in a single dimensional array reference called largestlocation.
*/
System.out.println(" The maximum value of the matrix is at following location (row,column)");
//invoke outputArray method, pass largestlocation array as argument.
/*invoke getDiagonal method, pass matrix as argument. Store the returned array
in a single dimensional array reference called diagonal.
*/
System.out.println(" The diagonal of the matrix contains following values");
//invoke outputArray method, pass diagonal array as argument.
/*invoke transpose method, pass matrix as argument. Store the returned 2D array
in a reference called transposed.
*/
System.out.println(" The resulting matrix after transposing original matrix");
//invoke outputMatrix method, pass transposed array as argument.
/*invoke find method, pass matrix and key value 5 as arguments. Store the returned array
in a single dimensional array reference called position.
*/
System.out.println(" The key value 5 is found at following location (row,column), (-1,-1) signifies nonexistence of search value.");
//invoke outputArray method, pass position array as argument.
/*invoke sortedRow method, pass matrix and row value 2 as arguments.
*/
System.out.println(" After sorting second row of the matrix");
//invoke outputArray method, pass matrix[2] as argument.
/*invoke rowSum method, pass matrix as argument. Store the returned array
in a single dimensional array reference called sums.
*/
System.out.println(" The sums of each row are... ");
//invoke outputArray method, pass sums array as argument.
/*invoke matrixCopy method, pass matrix as argument. Store the returned 2D array
in a reference called matrixCopy.
*/
System.out.println(" The copy of the original matrix is...");
//invoke outputMatrix method, pass matrixCopy array as argument.
}
/* populate the 2D array with random integers between 1 and 9
*/
public static void populateMatrix(int[][] data){
}
/* Output the 2D array to screen in following format
Assume array contains following data,
1 3 5
2 4 6
8 9 7
*/
public static void outputMatrix(int[][] data){
}
/* Returns the location of largest element of the 2D array.
This location is stored in an array of two elements, where
location[0] is the row, location[1] is the column.
Example
data[][] = 1 3 5 location[] = 2 0
2 4 6
9 7 2
*/
public static int[] findLocationOfLargest(int[][] data){
}
/* Returns the diagonal elements of a 2D array.
Example
data[][] = 1 3 5 diagonal[] = 1 4 9
2 4 6
3 7 9
*/
public static int[] getDiagonal(int[][] data){
}
/* Returns the transpose of the data array. You are changing row/column order to column/row order.
Example
data = 1 3 5 data^T = 1 2 8
2 4 6 3 4 9
8 9 7 5 6 7
*/
public static int[][] transpose(int[][] data){
}
/* Returns the location of search key
Example
data[][] = 1 3 5 key = 6 location[] = 1 2
2 4 6
9 7 2
*/
public static int[] find(int[][] data, int key){
}
/*
Sort a specific row in descending order. Uses bubble sort.
Invoke bubble sort with argument data[row].
*/
public static void sortedRow(int[][] data, int row){
}
/* Find sum of each row of the 2D array, returns an aray of sums
Example
data[][] = 1 3 5 sums[] = 9 12 19
2 4 6
3 7 9
*/
public static int[] rowSum(int[][] data){
}
/* Create a duplicate of the 2D array using System.arraycopy method.
returns the duplicate of the original 2D array.
data = 1 3 5 duplicate = 1 3 5
2 4 6 2 4 6
8 9 7 8 9 7
*/
public static int[][] matrixCopy(int[][] data){
}
/*
Copy and paste your bubble sort method you wrote in Lab 7
*/
public static void bubbleSort(int[] array){
}
/*
Copy and paste your outputArray method you wrote in Lab 7
*/
public static void outputArray(int[] array){
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
