// HouseTest2.java
//
// Tests constructor, toString, and static isValidHouse method
// Handles exceptions
import java.util.StringTokenizer;
public class HouseTest2
{
public static void main(String[] args)
{
if ( args.length == 0 )
{
System.out.println("Filename of data file needed"
+ " as command-line argument");
System.exit(0);
} // if
TextFileInput in = new TextFileInput(args[0]);
while ( true )
{
String line = in.readLine();
if ( line == null )
break;
testHouse(line);
} // while
} // method main
public static void testHouse(String line)
{
System.out.println("isValidHouse returns "
+ (House.isValidHouse(line)
?"TRUE"
:"FALSE")
+ " for: " + line);
try
{
System.out.println("Will now try to instantiate: " + line);
StringTokenizer st = new StringTokenizer(line, "|");
String zipCode = st.nextToken();
int price = Integer.parseInt(st.nextToken());
int numberOfRooms = Integer.parseInt(st.nextToken());
House house = new House(zipCode, price, numberOfRooms);
System.out.println("Instantiated: " + house);
} // try
catch ( RuntimeException re )
{
re.printStackTrace();
} // catch
} // method testHouse
} // class HouseTest2