/* * Two Comedians share a Microphone but don't take turns */ public class ConversationOne { Microphone mic; public static void main(String[] args) { new ConversationOne(); } public ConversationOne() { mic = new Microphone(); new Thread(new Comedian(Routine.A)).start(); new Thread(new Comedian(Routine.B)).start(); } // Each comedian has a routine class Comedian implements Runnable { String[] routine; public Comedian(String[] routine) { this.routine = routine; } public void run() { for (int i = 0; i < routine.length; i++) { mic.talk(routine[i]); try { Thread.sleep(200); } catch (InterruptedException e) {} } } } // Speak into the microphone class Microphone { public void talk(String what) { for (int i = 0; i < what.length(); i++) { System.out.print(what.charAt(i)); if (what.charAt(i) == ' ') { try { Thread.sleep(100); } catch (InterruptedException e) {} } } System.out.println(); } } }