Homework 11-28-2005
package homework_11_28_2005;
public class Counter {
private int value=0;
public Counter() {
initial();
}
public void increase() {
value++;
}
public void decrease() {
if(value >= 1)
value--;
else {
value=0;
System.out.println("Decrease counnt is negative");
}
}
public void initial() {
value=0;
}
public int getValue() {
return value;
}
public void printValue() {
System.out.println(" counter is " + value);
}
}
class CounterTest {
public static void main(String[] args){
Counter counter1 = new Counter();
Counter counter2 = new Counter();
counter1.increase();
counter1.decrease();
counter2.increase();
counter2.decrease();
System.out.println(" counter1 is " + counter1.getValue());
System.out.println(" counter2 is " + counter2.getValue());
if(counter1==counter2)
System.out.println(" equal ");
else
System.out.println(" not equal ");
}
}
public class Counter {
private int value=0;
public Counter() {
initial();
}
public void increase() {
value++;
}
public void decrease() {
if(value >= 1)
value--;
else {
value=0;
System.out.println("Decrease counnt is negative");
}
}
public void initial() {
value=0;
}
public int getValue() {
return value;
}
public void printValue() {
System.out.println(" counter is " + value);
}
}
class CounterTest {
public static void main(String[] args){
Counter counter1 = new Counter();
Counter counter2 = new Counter();
counter1.increase();
counter1.decrease();
counter2.increase();
counter2.decrease();
System.out.println(" counter1 is " + counter1.getValue());
System.out.println(" counter2 is " + counter2.getValue());
if(counter1==counter2)
System.out.println(" equal ");
else
System.out.println(" not equal ");
}
}
0 Comments:
張貼留言
<< Home