// This file contains a stub for a halting detector class. Since we // haven't yet fleshed out the details of what a halting detector // might look like, this one just tells its user that it is running // and (for now) gets the answer from him or her. import java.io.*; class HaltingDetector { // The "runsForever" method, which for now just gets its answer // from the user: public boolean runsForever( String method ) { try { BufferedReader keyboard = new BufferedReader( new InputStreamReader( System.in ) ); System.out.println( "HaltingDetector.runsForever given..." ); System.out.println( "'" + method + "'" ); System.out.print( "Does this run forever (y/n)? " ); String answer = keyboard.readLine(); if ( answer.equalsIgnoreCase( "y" ) ) { return true; } else if ( answer.equalsIgnoreCase( "n" ) ) { return false; } else { System.out.println( "Inavlid input '" + answer + "' -- I'll assume you meant 'n'." ); return false; } } catch ( IOException error ) { System.out.println( "Error reading user reply -- I'll assume the method doesn't run forever." ); return false; } } }