星期一, 12月 05, 2005

Homework 11.28.2005

public class Counter
{
private int count=0;
public Counter()
{
initial();
}
public void Increase()
{
count++;
}
public void Decrease()
{
if((count-1)>=0)
count--;
else if((count-1)<0)
{
System.out.println("Decrease counnter is negative");
}
}
public void initial()
{
count=0;
}
public int getValue()
{
return count;
}
public void printout()
{
System.out.println(" counter is " + count);
}
}
class CounterDemo
{
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("counter1 is equal counter2");
else
System.out.println("counter1 does not equal counter2");
}
}

0 Comments:

張貼留言

<< Home