/*
 * Two Comedians share a Microphone the cheap way
 */
public class ConversationTwo {
    Microphone mic;

    public static void main(String[] args) {
        new ConversationTwo();
    }

    public ConversationTwo() {
        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 -- one at a time!
    class Microphone {
        synchronized 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();
        }
    }
}

