问:我以为您必须确保电池未充满电,所以请执行!。然后增加mBarsCount
公共 类 GoKart {
public static final int MAX_ENERGY_BARS = 8 ; 私有字符串mColor ; 私人int mBarsCount ; 公共GoKart (字符串颜色){ mColor = color ; mBarsCount = 0 ; } public String getColor (){ return mColor ; }公共无效收费(){
mBarsCount = MAX_ENERGY_BARS ;
} public boolean isBatteryEmpty (){ return mBarsCount == 0 ; }公共布尔isFullyCharged (){而(!isFullyCharged ()){ mBarsCount + 1 ; } return mBarsCount == MAX_ENERGY_BARS ; }
答:您已经在该isFullyCharged方法中添加了代码以向Kart收费。应该在charge。
有道理?
公共 无效 收费() {
while (!isFullyCharged ()){ mBarsCount ++; } } public boolean isFullyCharged (){ return mBarsCount == MAX_ENERGY_BARS ; } }