bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 7, Problem 20E

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...

Blurred answer
Students have asked these similar questions
2. Perform resource allocation for the following project. Resource limits are 6 labors and 2 helpers. Legend: Activity Dur Resources G H 2 3 2L 1H 2L OH A 1 3L 1H + B D F J K 3 4 6 2 4 4L 2H 3L OH 4L 1H 2L 2H 4L 2H C E 2 2 I 1 2L 1H 3L 1H 5L 1H
Need Java method please. Thank you.
Need Java method please. Thank you.

Chapter 7 Solutions

Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License