gpt4 book ai didi

java - 如何检查值是否正确?

转载 作者:行者123 更新时间:2023-12-01 21:20:02 25 4
gpt4 key购买 nike

在我的 setValue 中,我在测试类中测试了不正确的错误,在我的测试类中 setValue 是 0,因此它预计为 00,但它在终端 01 中显示 我的老师将显示的值设置为newValue是什么意思,我尝试了this.value;。然而,它仍然给我错误,另外我尝试更改其中的符号,但老师说这是不正确的,我应该检查该值是否正确,然后将其设置为 newValue。我该如何解决这个问题?我很感激你的帮助。



private int minLimit;
private int maxLimit;
private int value;
private boolean wrapped;

public NumberDisplay(int minLimit, int maxLimit) throws IllegalValueException {

if (maxLimit > minLimit) {
this.minLimit = minLimit;
this.maxLimit = maxLimit - 1;
this.value = minLimit;
this.wrapped = true;
// creates new number display with the value minimum limit
// and the limits between maximum limit. if maximum limit is not greater than
// minimum limit
// it should throw exception

} else {
throw new IllegalValueException("felaktig");

}

}

public int getValue() {
return this.value;

// return the current value on display with integer number
}

public void setValue(int newValue) throws IllegalValueException {
if (newValue < minLimit || newValue > maxLimit) {


throw new IllegalValueException("Felaktig prova igen set time är felaktig");
// set the value on display to newValue. if newValue is less greater than minimum
// limit
// or greater than value from display then throw exception
} else {

if (newValue == minLimit) {
newValue = minLimit;
}

}

}

public String getDisplayValue() {

if (this.value < 11) {
return "0" + value;
} else {
return "" + value;
}
// return the current value with 0 infront of the value

}

public void increment() {

if (this.value == maxLimit) {

this.value = this.minLimit;
this.wrapped = true;
} else {

this.value = +1;
}

// increases the display with one value and checks if maximum limit is reached
// then
// it should be converted to minimum limit

// Consider to do the string delightful so all of values sets with as many as
// numbers
// the display should have. Values with low numbers should be zeros in front,
// e.g. clock 9 09:00

}

public boolean diWrapAround() {
if (this.value < maxLimit) {

return this.wrapped = true;
} else

return false;

}
// it should return true if the display reached over maximum limit and started
// from
// minimum limit , otherwise it should return false,
// use attribute wrapped to check boolean false or true.

}

最佳答案

enter code here public void setValue(int newValue) throws IllegalValueException {
if (newValue < minLimit || newValue > maxLimit) {

throw new IllegalValueException("Felaktig prova igen set time är felaktig");
// set the current display value to newValue. if newValue is less greater than
// minimum limit
// or greater than value from display then throw exception
} else {

if (newValue == minLimit ) {

this.value = newValue;
}

}

}

对于想知道答案的人,我更改了 this.value = newValue;检查该值是否正确

关于java - 如何检查值是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58854062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com