Question: Preliminaries Create a project submission folder, in the form Lab#FirstNameLastName. For example, mine would be Lab8DavidLiu Create an Eclipse Java Project. Add a Java class
Preliminaries
Create a project submission folder, in the form Lab#FirstNameLastName. For example, mine would be Lab8DavidLiu
Create an Eclipse Java Project.
Add a Java class named ArrayOps2D to your project
Add a Java class called Main to your project
Exercises
Part 1) The ArrayOps2D class 18 Points
ArrayOps2D holds the methods we will use to interact with 2DArrays. All of the methods will be public static. All methods should be written to use regular 2D arrays and ragged 2D arrays.
getTotal. This method should take a 2D array of doubles as an argument and return the sum of all the values in the 2D array.
getAverage. This method should take a 2D array of doubles as an argument and return the average of all the values. (Hint: you will need the sum and the total count of elements).
getRowTotal. This method should take a 2DArray of doubles and an int as arguments. It should return the sum of the row specified by the int (if the int is 1, then the row at index 1, like arr[1]).
findHighestValue. This method should accept a 2D array of doubles as an argument. It should find the largest value in the 2D array. Rather than returning the value, it should print out where it is located. So if the highest value is 25.5 in row 2 and column 3, it should print:
The highest value is 25.5, from row 2, column 3 This means you will need to keep track of the row and column (the indices being used in your double for loop), as well as the highest value.
findHighestValueInRow. This method should accept a 2D array of doubles and an int as arguments. It should find the highest value in the row specified by the int and then return the index where it occurred.
sequentialSearch2D. This method should accept a 2D array of doubles and a double as arguments. It should search the array for the value in the double argument. When it finds the value, it should print:
Value I found, at x, y! where I should be the value and x and y the row and column. So if it finds value 5.0 in row 1, column 6, it should print:
Value 5.0 found, at 1,6!
Part 2) Main 2 Points
The second part of the lab is focused on testing the ArrayOps2D class.
Make a 2D array and a 2D ragged array. They can be whatever you wish, but could be something like:
double[][] simple2D = {{3,4,5}, {6,7,8}, {9,9,1}};
double[][] ragged2D = new ragged2D[2][];
ragged2D[0] = {1,2,3,3,3,3};
ragged2D[1] = {3,4,5,8,9};
ragged2D[2] = {8,9,1,};
Call all methods, using both simple2D and ragged2D. For all methods that return something, you should print the result. It is recommended you do something like this for easy reading and testing:
2D Results
---
Print out the results for the 2D array
---
Ragged Results
---
Print out the results for the ragged array
While it is not required, it is recommended that you use a few different array set ups, just for the sake of testing correctness.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
