问:这要求我设置一个辅助方法,如果mBarsCount为Max,则返回true,在代码中我这样做
GoKart.java
公共 类 GoKart {
public static final int MAX_BARS = 8 ; 私有字符串mColor ; 私人int mBarsCount ; 公共GoKart (字符串颜色){ mColor = color ; mBarsCount = 0 ; } public boolean isBatteryEmpty (){ return mBarsCount == 0 ; } public boolean isFullyCharger
(){
return mBarsCount = MAX_BARS ; } public String getColor (){ return mColor ; }公共无效收费(){ mBarsCount = MAX_BARS ; } }
答:第一项任务应该绝对正确:
public boolean isBatteryEmpty (){
return mBarsCount == 0 ; //此行的结果为true //所以boolean isBatteryEmpty为true }
第二项任务的代码需要稍作改动:)
public boolean isFullyCharged (){
//您有isFullyCharger
//您需要isFullyCharged
return mBarsCount == MAX_BARS ; //这里一切都将变得轻松而伟大}