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: 3565860 • 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.

Bowl Class:

I tried:

public static boolean mostBowlsFull(Bowl[] bowls){

int i = bowls.length;

int count = 0;

for(int j = 0; j<i; j++){

if(!array[j].getEmpty()){

count++;

}

}

return (count > i/2);

}

but it's giving me errors. Help please.

Explanation / Answer

======================================

Your code is perfect correct , only one typo error, i mentioned in bold font

======================================

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

============================================

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