1 /* 2 * File: ConsoleTest.java 3 * 4 * Test program for custom Console class 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import corejava.Console; 11 12 public class ConsoleTest { 13 14 public static void main( String args[] ) { 15 16 boolean done; 17 int someInt; 18 double someDouble; 19 20 // readString( String ) method: 21 System.out.println( Console.readString( "Type a string: " ) ); 22 23 // readString() method: 24 Console.printPrompt( "Type a string: " ); 25 System.out.println( Console.readString() ); 26 27 // readInt( String ) method: 28 System.out.println( Console.readInt( "Type an integer: " ) ); 29 30 // readInt() method: 31 done = false; 32 while ( !done ) { 33 try { 34 Console.printPrompt( "Type an integer: " ); 35 someInt = Console.readInt(); 36 System.out.println( someInt ); 37 done = true; 38 } catch ( NumberFormatException e ) { 39 System.out.println( "Not enough coffee this morning, eh?" ); 40 System.out.println( "Please try again!" ); 41 } 42 } 43 44 // readDouble( String ) method: 45 System.out.println( Console.readDouble( "Type a float: " ) ); 46 47 // readDouble() method: 48 done = false; 49 while ( !done ) { 50 try { 51 Console.printPrompt( "Type a float: " ); 52 someDouble = Console.readDouble(); 53 System.out.println( someDouble ); 54 done = true; 55 } catch ( NumberFormatException e ) { 56 System.out.println( "Having a bad day?" ); 57 System.out.println( "Let's try that again!" ); 58 } 59 } 60 61 } 62 63 } // end class ConsoleTest