Lab Counter II
package s9226307;import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class s9226307 {
private int number;
public s9226307()
{
}
public void readInput() throws IOException
{
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System. in));
System.out.println("Enter a number.");
System.out.println("Do not use a comma.");
number = keyboard.read();
}
public void reset()
{
number = 0 ;
}
public void inc()
{
number = number + 1 ;
}
public void dec()
{
number = number - 1 ;
}
public void writeOutput()
{
System.out.println("counter number is " + number);
}
public boolean equals(s9226307 otherCounter)
{
return this.number == otherCounter.number;
}
public void resetToZero()
{
number = 0;
}
public String toString()
{
return Integer.toString(number) ;
}
}
-------------------------------------------------------------------------------------
package s9226307;
import java.io.IOException;
public class ccc
{
public static void main(String[] args) throws IOException
{
s9226340 number1 = new s9226307(),
number2 = new s9226307();
number1.inc();
number2.inc();
if (number1.equals(number2))
{
System.out.println( number1 + " is equal to " + number2);
}
else
{
System.out.println( number1 + " is not equal to " + number2);
}
number2.inc();
number1.dec();
if (number1.equals(number2))
{
System.out.println( number1 + " is equal to " + number2);
}
else
{
System.out.println( number1 + " is not equal to " + number2);
}
}
}
0 Comments:
Post a Comment
<< Home