좋아요,이 프로그램 CounterTester.java가 다운되었지만 출력물에 프로그램이 원하는 방식으로 늘어나고 있지만 방식이 줄지 않습니다. 그것을 원한다.CounterTester.java 출력이 정확하지만 정확히 감소하지 않습니다
아무쪼록 잘 부탁드립니다.
/**
* This program is used to test the Counter class. It constructs the a counter
* using both constructors provided by the Counter class.
*
*/
public class CounterTester
{
static int myCount;
public CounterTester() {
int init = 1;
myCount = init;
}
public CounterTester(int i) {
}
public static void main(String[] args)
{
CounterTester counter = new CounterTester(); //create a new counter with a step value of 1
counter.increase(myCount); //add 1
System.out.println("Expected Count: 1 -----> Actual Count: " + counter.getCount());
counter.increase(myCount++); //add 1
System.out.println("Expected Count: 2 -----> Actual Count: " + counter.getCount());
counter.decrease(); //subtract 1
System.out.println("Expected Count: 1 -----> Actual Count: " + counter.getCount());
counter = new CounterTester(10); //create a new counter with a step value of 10
System.out.println("Expected Count: 0 -----> Actual Count: " + counter.getCount());
counter.increase(myCount++); //add 10
System.out.println("Expected Count: 10 ----> Actual Count: " + counter.getCount());
counter.decrease(); //subtract 10
System.out.println("Expected Count: 0 -----> Actual Count: " + counter.getCount());
counter.decrease(); //subtract 10
System.out.println("Expected Count: -10 -----> Actual Count: " + counter.getCount());
}
private String getCount() {
return ""+myCount;
}
private void decrease() {
myCount--;
}
private void increase(int i) {
myCount++;
}
public void reset() {
}
}
감사합니다.
힌트 : 생성자를보세요.'public CounterTester (int i)'이 값으로 무엇을해야합니까? –
당신의 과제는 '// TODO'라고 쓰여진 공란을 채우는 것입니다. (카운트를 추적하기위한 필드가 필요합니다). 'return null'은 일시적이며, 단지'NULL'을 출력 할 것이기 때문에 무언가에 의해 대체되어야합니다. – zapl
zapl - // TODO 영역에서 계산을 사용해야합니까? 나는 일종의 우둔한 사람이다. 나는 확실히 초보자이다. –