帮帮我
我是个新手
照抄书上然后改点了做了个小实验
public class CyberPet
{
private boolean isEating=true;
private boolean isSleeping=false;
private String name= "noname ";
private String food= "nothing ";
public CyberPet(String str)
{
name=str;
}
public void setName(String str)
{
name=str;
}
public String getName()
{
return name;
}
public void eat()
{
isEating=true;
isSleeping=false;
return;
}
public void sleep()
{
isSleeping=true;
isEating=false;
return;
}
public String eat(String str)
{
food=str;
}
public void setFood(String str)
{
food=str;
}
public String getFood()
{
return food;
}
public String getState()
{
if (isEating)
return "Eating ";
if (isSleeping)
return "Sleeping ";
return "Error in State ";
}
}
提示:
CyberPet.java:33 missing return statement
帮帮我
------解决方案-------------------- public String eat(String str) {
food = str;
}
这个方法有问题,改成
public void eat(String str) {
food = str;
}
------解决方案--------------------public String eat(String str)
{
food=str;
}
改为:
public void eat(String str)
{
food=str;
}