importjava.util.ArrayList;classCookieMonster{Stringname;ArrayListbelly;intbellySize;intbellyIndex;intgreedLevel;CookieMonster(){this.name="UNKNOWN";this.belly=nul...
import java.util.ArrayList;
class CookieMonster{
String name;
ArrayList belly;
int bellySize;
int bellyIndex;
int greedLevel;
CookieMonster(){
this.name = "UNKNOWN";
this.belly = null;
this.bellySize = 5;
this.bellyIndex = 0;
this.greedLevel = 1;
}
CookieMonster(String ne){
this.name = ne;
this.belly = null;
this.bellySize = 5;
this.bellyIndex = 0;
this.greedLevel = 1;
}
CookieMonster(String ne, int bs, int gl){
this.name = ne;
this.belly = null;
this.bellySize = bs;
this.bellyIndex = 0;
this.greedLevel = gl;
}
//cosstructors
String name(){
}
ArrayList belly(){
}
int bellySize(){
}
int bellyIndex(){
}
int greedLevel(){
}
//method
public String toString(){
String answer;
if (this.greedLevel = 0)
answer = "Cookie Monster" + this.name + "with belly size" +
this.bellySize + "who is satisfied";
else
answer ="Cookie Monster" + this.name + "with belly size" +
this.bellySize + "who wants" + this.greedLevel + "more cookies";
return answer;
}
}
47行为什么错了?
展开