/* * File: ConsoleTest.java * * Test program for custom Console class * * Copyright: Northeast Parallel Architectures Center * */ import corejava.Console; public class ConsoleTest { public static void main( String args[] ) { boolean done; int someInt; double someDouble; // readString( String ) method: System.out.println( Console.readString( "Type a string: " ) ); // readString() method: Console.printPrompt( "Type a string: " ); System.out.println( Console.readString() ); // readInt( String ) method: System.out.println( Console.readInt( "Type an integer: " ) ); // readInt() method: done = false; while ( !done ) { try { Console.printPrompt( "Type an integer: " ); someInt = Console.readInt(); System.out.println( someInt ); done = true; } catch ( NumberFormatException e ) { System.out.println( "Not enough coffee this morning, eh?" ); System.out.println( "Please try again!" ); } } // readDouble( String ) method: System.out.println( Console.readDouble( "Type a float: " ) ); // readDouble() method: done = false; while ( !done ) { try { Console.printPrompt( "Type a float: " ); someDouble = Console.readDouble(); System.out.println( someDouble ); done = true; } catch ( NumberFormatException e ) { System.out.println( "Having a bad day?" ); System.out.println( "Let's try that again!" ); } } } } // end class ConsoleTest