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);
}
============================================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.