// File: useful_io_subunit.java // // Author: Rahul Simha // Created: Aug 18, 1998 // // Illustrates packages package useful_io_pack; import java.io.*; import java.util.*; public class useful_io_subunit { // Read a string from the screen. public static String read_string (String prompt) { System.out.print (prompt); InputStreamReader isr = new InputStreamReader (System.in); LineNumberReader lr = new LineNumberReader (isr); try { String s = lr.readLine (); return s; } catch (IOException e) { System.out.println ("gwu_io::read_string: cannot read\n"); System.exit (0); return ""; } } // Parse a string for a property. public static double read_property (String in_string, String property) { StringTokenizer st = new StringTokenizer (in_string); String first_part = st.nextToken ("="); first_part = first_part.trim (); if (!first_part.equals (property)){ System.out.println ("Improper string: " + in_string); System.exit (0); } String second_part = st.nextToken (" =\t\n\r"); second_part = second_part.trim(); try { Double d = Double.valueOf (second_part); return d.doubleValue(); } catch (NumberFormatException e) { System.out.println ("Second part not a number: " + second_part); System.exit (0); } return 0; } } // End of class useful_io_subunit