// HouseTest3.java
//
// Tests setPrice method,
// assuming a valid constructor and toString method.
import java.util.StringTokenizer;
public class HouseTest3
{
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;
House house = makeHouse(line);
if ( house != null )
{
while ( ConsoleInput.askYesNo(
"Change price for this House?") )
testSetPrice(house);
} // if
} // while
} // method main
private static void testSetPrice(House house)
{
String numberText = ConsoleInput.ask("New price?");
try {
int number = Integer.parseInt(numberText);
house.setPrice(number);
System.out.println("Changed price: " + house);
} // try
catch ( RuntimeException re )
{
re.printStackTrace();
System.out.println("Price unchanged: " + house);
} // catch
} // method testSetPrice
private static House makeHouse(String 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);
return house;
} // try
catch ( RuntimeException re )
{
re.printStackTrace();
return null;
} // catch
} // method makeHouse
} // class HouseTest3