Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5) Consider the following function: public static boolean mystery(Color[][][] gr

ID: 3858004 • Letter: 5

Question

5)   Consider the following function:

public static boolean mystery(Color[][][] grid, Color col, int num) {

   int x = 0;

   for (int i=0; i<grid.length; i++) {

       for (int j=0; j<grid[i].length; j++) {

           for (int k=0; k<grid[i][j].length; j++ k++) {

               if (grid[i][j][k] == col) {

                   x++;

               }

           }

       }

   }

   return x >= num;

}

What happens if grid contains a null value?

Describe an input that makes this function return false.

Describe an input that makes this function return true.

Summarize what this function does.

Explanation / Answer

a) If the grid contains a null value nothing happens those values will be skipped under the condition

b)mystery({{{red,blue},{red,yellow}},{{green,voilet},{pink,grey}}},grey,3) this will return a false since the grey color count is not greater than 3

c) mystery({{{red,blue},{greyyellow}},{{grey,voilet},{pink,grey}}},grey,3) this will return a false since the grey color count is greater than or equal to 3

d)

breif description :

In simple words this function checks whether the given color count is greater than given number if greater or equal this function returns true or else false.

A full-length description :

The grid stores the color values in a three dimensional array, the given function takes input a 3-d array, a color and a number, what this function does is it loops through each and every element in the array(here grid) and if the value in any location of the grid is equal to "col" then it increments the variable x after the enter loop iteration it returns a value false if the x value is less than "num" value, it returns true if the x value is greater than or equal to "num" value

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote