/////////////////////////////////////////////////////////////////////
//
// File: hw1.java
//
// Purpose: (proj1) hw1 (Hello World) class, interface independent.
// It is an InputHandler, which is an abstract class.
//
// Authors: txe Travis Emmitt
//
// Modifications:
// 09-SEP-1998 txe Initial creation (on pc)
// 10-SEP-1998 txe Added input and loops (change of specs)
// 11-SEP-1998 txe Adding stand/applet support, moved TravIO out
// 13-SEP-1998 txe Moved to separate file (interface independent)
// 14-SEP-1998 txe Added comments.
//
/////////////////////////////////////////////////////////////////////
import TravIO;
class hw1 extends InputHandler {
private static final int min_value = 0;
private static final int max_value = (2 << (16 - 1)) - 1; // 65535
private TravIO io;
// The constructor associates the handler with an interface (either
// standalone or applet) and then prints initial instructions.
public hw1 (TravIO travio) {
io = travio;
io.Println ("Enter integers between " + min_value + " and " + max_value);
}
// HandleInput() reads in input from the interface. If the input
// is outside of the specified min/max range, we print an error
// message and continue. Otherwise, if the input is even, we print
// "Hello World" and continue; it the input is odd, we print
// "Goodbye World" and exit the program.
public void HandleInput () {
try {
int input = Integer.parseInt (io.Readln());
if (input < min_value || input > max_value) {
io.Println ("Error: Input not in range " + min_value + ".." + max_value);
}
else if (input % 2 > 0) {
io.Println ("Goodbye World");
io.Exit ();
}
else {
io.Println ("Hello World");
}
}
catch (Exception e) {
io.Println ("Error: Input is not an integer");
}
}
}
///////////////////////////////////////////////////////////////////////