TO FIND THE NEXT OR DIFFERENT PROJECT CLICK ON THE SEARCH BUTTON ON THE TOP RIGHT MENU AND SEARCH USING COURSE CODE OR PROJECT TITLE.
$15
Lab Objectives
Be able to declare two-dimensional arrays
Be able to pass two-dimensional arrays to methods
Be able to return a two-dimensional array from methods
Be able to process a two-dimensional array in a Java Method
Be able to work with individual rows and columns in a two-dimensional array
Introduction
Writing methods that take multi-dimensional arrays as parameters and/or return multi-dimensional arrays is similar to working with single-dimensional arrays.
The syntax for a method that accepts a two-dimensional array as a parameter is as follows:
returnType methodName( arrayType[][] arrayParameterName )
The syntax for a method that returns a two-dimensional array is the following:
returnArrayType [][] methodName( arrayType [ ][ ] arrayParameterName )
In this Lab, you will work with a 4-row, 20-column, two-dimensional array of integers. You will write methods that perform the following operations:
To visualize how the two-dimensional array is working, your result will animate a bar graph. The
Code for the bar graph is provided to you as BarChart.java. So, the framework for this lab will animate your algorithm, which will support you in checking the accuracy of your Java program.
Lab Instructions
The source files required to complete this activity has been provided. Copy both the files to a folder in your computer. It is important that both the files stay in the same folder.
Open the TwoDimArrayPractice.java source file. For your convenience, the sample code for task number 1 has been provided under comment 1. inside the fillValues() method. You may use this as a model for completing the remaining four tasks. You will need to complete those rest of the four tasks in four other methods. In each one of these four remaining tasks, you will fill in the code for a method that will manipulate an existing array of 4 rows and 20 columns. You need not instantiate the two-dimensional array. That has been done for you.
SAMPLE OUTPUT:
Following shows a sample output from the fillValues( ) method.
Task #1 Print Array to Console.
public void printArray( )
This method is under comment 2.
OUTPUT:
Following shows the screen capture of the required output from the printArray( ) method.
Task #2 Set All Elements in A Row to A Specified Value
OUTPUT:
Following shows the screen capture of the required output from setValues(65, 2).
Task #3 Find Minimum Value in the Specified Column
Following shows screen shot of the output for findMinimum(3).
OUTPUT:
Task #4 Find Frequency of a Given Value in the Array
OUTPUT:
Following shows screen capture for countFound(66).
The two .java files (TwoDimArrayPrac.java and BarChart.java) running under the same project will animate your algorithm so that you can visually watch your code work. For this to happen, make sure that your single or nested for loops call the method animate. The arguments that you send to animate are not always the same and the location of the call to animate will differ depending on the task you are coding.
Since the values in the two-dimensional array are randomly generated, the values will be different each time the program runs. To test any of the methods that you have implemented, please click on the appropriate button.