星期一, 5月 08, 2006

Counter2

package Lab7;

public class Counter2 {
private/** static*/int count=0 ;
public void reset()
{
count = 0;
// System.out.println("reset counter,");
}

public void inc()
{
++count ;
// System.out.println("counter+1,");
}

public void dec()
{
--count ;
// System.out.println("counter-1,");
}

public void output()
{
System.out.println("counter now is :"+ count);
}

public int getCounter()
{
return count ;
}

public boolean equalS(Counter2 counterX)
{

return this.count == counterX.count;
}
}
-----------
package Lab7;

public class Counter2Demo {

public static void main(String[] args) {
Counter2 counterX= new Counter2();
Counter2 counterB= new Counter2();
counterX.inc();
counterX.inc();
counterX.inc();
//counterA.reset();
counterX.output();
counterB.output();
System.out.println("counterA & counter equals : "+counterX.equalS(counterB));
}
}

0 Comments:

張貼留言

<< Home

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Taiwan License.