
Explanation of Solution
Method definition for “findFigure”:
/* Method definition for "findFigure" */
public static double[][] findFigure(double[][] picture, double threshold)
{
/* Compute maximum row value */
int maximumRow = picture.length;
/* Compute maximum column value */
int maximumColumn = picture[0].length;
/* Create two dimensional array for resulting array */
double[][] resultantArray = new double[maximumRow][maximumColumn];
/* Assign "total" to "0.0" */
double total = 0.0;
/* Compute total value for "picture" array */
for(int row = 0; row < maximumRow; row++)
{
for(int col = 0; col < maximumColumn; col++)
{
total += picture[row][col];
}
}
/* Compute average for "picture" array */
double average = total/(maximumRow * maximumColumn);
/* Compute the threshold times */
double thresholdTimes = average * threshold;
/* Display the average and threshold times of all average for "picture" array */
System.out.println("The average value is " + average + " anything above "+ thresholdTimes + " will be 1.0");
/* Check the condition whether value of "picture" array exceeds or not the threshold times the average of all values in "picture" */
for(int row = 0; row < maximumRow; row++)
{
for(int col = 0; col < maximumColumn; col++)
{
/* If the value in "picture" array is greater "thresholdTimes", then */
if(picture[row][col] > thresholdTimes)
{
/* set "resultantArray[row][col]" to "1.0" */
resultantArray[row][col] = 1.0;
}
//Otherwise
else
{
/* Set "resultantArray[row][col]" to "0.0" */
resultantArray[row][col] = 0.0;
}
}
}
/* Returns the resulting array */
return resultantArray;
}
Complete code:
The complete code for after implementing “findFigure” method is given below:
//Define "findFigureTest" class
public class findFigureTest
{
/* Method definition for "findFigure" */
public static double[][] findFigure(double[][] picture, double threshold)
{
/* Compute maximum row value */
int maximumRow = picture.length;
/* Compute maximum column value */
int maximumColumn = picture[0].length;
/* Create two dimensional array for resulting array */
double[][] resultantArray = new double[maximumRow][maximumColumn];
/* Assign "total" to "0.0" */
double total = 0.0;
/* Compute total value for "picture" array */
for(int row = 0; row < maximumRow; row++)
{
for(int col = 0; col < maximumColumn; col++)
{
total += picture[row][col];
}
}
/* Compute average for "picture" array */
double average = total/(maximumRow * maximumColumn);
/* Compute the threshold times */
double thresholdTimes = average * threshold;
/* Display the average and threshold times of all average for "picture" array */
System.out.println("The average value is " + average + " anything above "+ thresholdTimes + " will be 1.0");
/* Check the condition whether value of "picture" array exceeds or not the threshold times the average of all values in "picture" */
for(int row = 0; row < maximumRow; row++)
{
for(int col = 0; col < maximumColumn; col++)
{
/* If the value in "picture" array is greater "thresholdTimes", then */
if(picture[row][col] > thresholdTimes)
{
/* set "resultantArray[row][col]" to "1.0" */
resultantArray[row][col] = 1.0;
}
//Otherwise
else
{
/* Set "resultantArray[row][col]" to "0...
Want to see the full answer?
Check out a sample textbook solution
Chapter 7 Solutions
Java: An Introduction To Problem Solving And Programming Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (8th Edition)
Problem Solving with C++ (10th Edition)
SURVEY OF OPERATING SYSTEMS
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Python (4th Edition)
Introduction To Programming Using Visual Basic (11th Edition)