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

Write a static method named mostBowlsFull, to be added to the Bowl class, which

ID: 3565584 • Letter: W

Question

Write a static method named mostBowlsFull, to be added to the Bowl class, which is passed an array of Bowl objects, and returns true if a strict majority of the Bowls in the array are not empty. Thus if the array consists of 11 bowls and 6 are not empty, your method should return true, but if the array consists of 12 bowls and 6 (or fewer) are not empty, your method should return false.

public static boolean mostBowlsFull(Bowl[] array){
int len = array.length();
int count = 0;
for(int i=0; i if(!array[i].isEmpty()){
count++;
}   
}
return (count > len/2));
}
What is wrong with that ^
Class:

Explanation / Answer

public static boolean mostBowlsFull(Bowl[] array){
   int len = array.length;
   int count = 0;
   for(int i=0; i < len; i++)
       if(!array[i].getEmpty()){
           count++;
       }   
return (count > len/2);
}

/*

You should return (count > len / 2), instead of (count > len), because you have to check whether the number of non-empty bowls is more than 'half' the total number of bowls or not!!

*/

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