我正在创建一个四位数字类(如时钟),同时从两位数字类调用方法。
四位数类别有两个段。当第一段达到我设定的最大值时,第二段必须增加一。
这些是我第一个类的方法:
/*
* 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;}
}
这是我的第二个四位数类(class)的内容。
/*
* method to set the increment
*/
public void setIncrement(int increment){
rightSegment.setValuePlusOne();
if(increment == 0)
leftSegment.setValuePlusOne();
}
我认为我的增量== 0可能有问题。当我尝试时它无法编译 if(rightsegment.setValuePlusOne()==0)
任何建议都会有所帮助。谢谢!!
最佳答案
setValuePlusOne(...) 不返回任何内容。在 if 之前调用 setValuePlusOne,然后在 if 中使用 (rightsegment.getValue() == 0)。
关于java - 从另一个类调用设置值方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36380406/