Monday, December 05, 2005

Homework 11-28-2005

public class Counter {
private int count;
public Counter() {
}
public void setZero()
{
count=0;
}
public void countIncrease()
{
count=count+1;
}
public void countDecrease()
{
if((count-1)>=0)
count=count-1;
else if((count-1)<0)
System.out.println("Decrease counnt is negative");
}
public int accessor()
{
return count;
}
public void out()
{
System.out.println(""+count);
}
public static void main(String[] args) {
}
}


public static void main(String[] args) {
Counter count1 = new Counter(),count2=new Counter();
System.out.println("count set to zero.");
count1.setZero();
System.out.print("coun1=");
count1.out();
System.out.print("coun2=");
count2.setZero();
count2.out();
System.out.println("count is increase or dercase");
System.out.print("coun1=");
count1.countIncrease();
count1.countIncrease();
count1.out();
System.out.print("coun2=");
count2.countIncrease();
count2.countDecrease();
count2.out();
if(count1 ==count2)
System.out.println("count1 is equal count2");
else
System.out.println("count1 does not equal count2");
count2.countIncrease();
count2.accessor();
}

0 Comments:

Post a Comment

<< Home