/**
 * Class for "The House That Jack Built" by Jonathan Swift
 */
public class JackHouse {

    public static final String[][] Scene = {
        {"This is", " ",     " the farmer sowing the corn,"      },
        {"That", " kept",    " the cock that crowed in the morn,"},
        {"That", " waked",   " the priest all shaven and shorn," },
        {"That", " married", " the man all tattered and torn,"   },
        {"That", " kissed",  " the maiden all forlorn,"          },
        {"That", " milked",  " the cow with the crumpled horn,"  },
        {"That", " tossed",  " the dog,"                         },
        {"That", " worried", " the cat,"                         },
        {"That", " killed",  " the rat,"                         },
        {"That", " ate",     " the malt"                         },
        {"That", " lay",     " in the house that Jack built."    }
    };


    /**$ENTRY Go {
      *  = <Title> <JonathanSwift>;
      *}
      */
    public static void main (String args[]) {
        Title();
        JonathanSwift();
    }


    /**Title {
      *  = <Out ('     The House That Jack Built')
      *         ('          Jonathan Swift'      )>;
      *}
      */
    public static void Title() {
        System.out.println("     The House That Jack Built");
        System.out.println("          Jonathan Swift");
    }


    /**Paragraph {
      * = <NL> <NL>;
      *}
      */
    public static void Paragraph() {
        NL();
        NL();
    }


    /**NL {
      * = <Prout >;
      *}
      */
    public static void NL() {
        System.out.println();
    }
    

    /**JonathanSwift {
      *  = <Loop <Scene>>;
      *}
      */
    public static void JonathanSwift() {
        Loop(0);
    }


    /**Loop {
      * ("This is" 'in the house that Jack built.') =
      *         <Paragraph>
      *         <Out ("This is" 'the house that Jack built.')>;
      *
      * e.Couplet = <Next e.Couplet>
      *             <Paragraph>
      *             <Out e.Couplet>;
      *}
      */
    public static void Loop(int Couplet) {
        int nScene = Scene.length;
        if (Couplet == nScene -1) {
            Paragraph();
            System.out.println("This is the house that Jack built.");
            }
            else {
                Next(Couplet);
                Paragraph();
                Out(Couplet);
            }
    }


    /**Next {
      *   (e.first) ("That" s.1 e.2) e.text =
      *       <Loop ("This is"  e.2) e.text>;
      *}
      */
    public static void Next(int Couplet) {
        Loop(Couplet + 1);
    }


    /**Out {
      *   = ;
      *  (e.first) e.text = <Prout e.first>
      *                     <Out e.text>;
      *}
      */
    public static void Out(int Couplet) {
        int nScene = Scene.length;
        System.out.println("This is" + Scene[Couplet][2]);
        for (int j=Couplet+1; j<nScene; j++) {
            System.out.println(Scene[j][0] +
                               Scene[j][1] +
                               Scene[j][2] );
        }
    }
}

//--------------------------------------------------
/*
*$MST_FROM_ENTRY;
$EXTRN Prout;

$ENTRY Go { 
  = <Title> <JonathanSwift>;
}

Title {  
  = <Out ('     The House That Jack Built')
         ('          Jonathan Swift'      )>;
}

Paragraph {
 = <NL> <NL>;
}

NL {
 = <Prout >;
}

Scene { = 
("This is"           'the farmer sowing the corn,'  " "  )
("That"    "kept"    'the cock that crowed in the morn,' )
("That"    "waked"   'the priest all shaven and shorn,'  )
("That"    "married" 'the man all tattered and torn,'    )
("That"    "kissed"  'the maiden all forlorn,'           )
("That"    "milked"  'the cow with the crumpled horn,'   )
("That"    "tossed"  'the dog,'                          )
("That"    "worried" 'the cat,'                          )
("That"    "killed"  'the rat,'                          )
("That"    "ate"     'the malt'                          )
("That"    "lay"     'in the house that Jack built.'     )
}

JonathanSwift {
  = <Loop <Scene>>;
}

Loop {
 ("This is" 'in the house that Jack built.') =
         <Paragraph>
         <Out ("This is" 'the house that Jack built.')>;

 e.Couplet = <Next e.Couplet>
             <Paragraph>
             <Out e.Couplet>;
}

Next {
   (e.first) ("That" s.1 e.2) e.text =
       <Loop ("This is"  e.2) e.text>;
}

Out {
   = ;
  (e.first) e.text = <Prout e.first>
                     <Out e.text>;
}
*/