// DotsAndDollars.java (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2004-09-14 File created. // 2005-05-15 Last modification. import java.util.* ; class ThreadToPrintDots extends Thread { boolean must_print_dots = true ; public void stop_this_thread() { must_print_dots = false ; } public void run() { while ( must_print_dots == true ) { try { Thread.sleep( 1000 ) ; // Wait one second. } catch ( InterruptedException caught_exception ) { } System.out.print( " ." ) ; } } } class ThreadToPrintDollarSigns extends Thread { boolean must_print_dollar_signs = true ; public void stop_this_thread() { must_print_dollar_signs = false ; } public void run() { while ( must_print_dollar_signs == true ) { try { Thread.sleep( 4050 ) ; // Wait 4.05 seconds. } catch ( InterruptedException caught_exception ) { } System.out.print( " $" ) ; } } } class DotsAndDollars { public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; ThreadToPrintDots thread_to_print_dots = new ThreadToPrintDots() ; ThreadToPrintDollarSigns thread_to_print_dollar_signs = new ThreadToPrintDollarSigns() ; thread_to_print_dots.start() ; thread_to_print_dollar_signs.start() ; System.out.print( "\n Press the Enter key to stop the program. \n\n" ) ; String any_string_from_keyboard = keyboard.nextLine() ; thread_to_print_dots.stop_this_thread() ; thread_to_print_dollar_signs.stop_this_thread() ; } }