HW 12-12-2005 Counter II
package counter;
public class counter1 {
public static void main(String[] args) {
counter count1 = new counter(),
count2 = new counter();
count1.increment();
count1.decrement();
count2.increment();
count2.decrement();
if (count1.equals(count2))
System.out.println("The are equal");
else
System.out.println("The are not equal");
count2.increment();
if (count1.equals(count2)) {
System.out.println("The are equal");
} else {
System.out.println("The are not equal");
}
}
}
-----------------------------------------------------
package counter;
public class counter {
private int count = 0;
public void resetToZero() {
count = 0;
}
public void increment() {
count++;
}
public void decrement() {
if (count <= 0)
count = 0;
else
count--;
}
public int getValue()
{
return count;
}
public void output() {
System.out.println(" The counter is " + count);
}
public boolean equals(counter otherCounter)
{
return this.count == otherCounter.count;
}
public String toString() {
return Integer.toString(count);
}
}
public class counter1 {
public static void main(String[] args) {
counter count1 = new counter(),
count2 = new counter();
count1.increment();
count1.decrement();
count2.increment();
count2.decrement();
if (count1.equals(count2))
System.out.println("The are equal");
else
System.out.println("The are not equal");
count2.increment();
if (count1.equals(count2)) {
System.out.println("The are equal");
} else {
System.out.println("The are not equal");
}
}
}
-----------------------------------------------------
package counter;
public class counter {
private int count = 0;
public void resetToZero() {
count = 0;
}
public void increment() {
count++;
}
public void decrement() {
if (count <= 0)
count = 0;
else
count--;
}
public int getValue()
{
return count;
}
public void output() {
System.out.println(" The counter is " + count);
}
public boolean equals(counter otherCounter)
{
return this.count == otherCounter.count;
}
public String toString() {
return Integer.toString(count);
}
}
0 Comments:
張貼留言
<< Home