我從兩位數類中調用方法時創建了一個四位數類(如時鐘)。從另一個類調用設置值方法
四位數類有兩個段。當第一段達到我設定的最大值時,第二段必須加1。
這些都是我的方法從我第一類:
/*
* method to set the value
*/
public void setValue(int anyValue){
if((anyValue < TOO_HIGH) && (anyValue >= 0)){
value = anyValue;}
}
/*
* method to set the value plus one
*/
public void setValuePlusOne(){
int tempValue = value + 1;
if(tempValue < TOO_HIGH){
value = tempValue;}
else{
value = 0;
// value = tempValue % TOO_HIGH;}
}
這是我的第二個四位數級。
/*
* method to set the increment
*/
public void setIncrement(int increment){
rightSegment.setValuePlusOne();
if(increment == 0)
leftSegment.setValuePlusOne();
}
我覺得可能是壞了我的增量== 0,當我嘗試 它不能編譯,如果(rightsegment.setValuePlusOne()== 0)
任何意見會有所幫助。謝謝!!
'rightSegment.setValuePlusOne();'應該返回'int'進行編譯。 –
請使用自動縮進和格式化您的代碼的IDE。你發佈的代碼有點混亂,特別是右花括號很混亂。 –
那麼......爲什麼不使用兩個單獨的類,而不是將它們合併爲一個,並使用if語句來控制增量?對程序目的的更多瞭解將有助於指導您走向正確的方向。 –