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

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

    public static final int size = scene.length;

/*   
    public static void main (String args[]) {
      try {
        int n = Integer.parseInt(args[0]);
        System.out.print(new Swift2(n).getText());
      }
      catch (Throwable th) {
        System.out.println ("Illegal arguments");
        System.out.println ("Correct usage is:");
        System.out.println ("  java swift2 N");
        System.out.println ("where N is a number from 0 to "+size);
      }
    }
*/ 

    public static void main (String args[]) {
        // go();
        // go1(4);
        go1(size);
    }

    public static void go() {
      System.out.print(all(size-4));
  //  System.out.print(new Swift2(4).getText());
      }


    public static void go1(int n) {
    for (int i=0; i<=size; i++)
      if (i==n) {
        System.out.print(all(size-i));
        return;
      }
    }

    public static String all(int s) {
        return  "\n\n" +
                "     The House That Jack Built\n" +
                "          Jonathan Swift\n" +
                poem(s);
    }
    public static String poem(int p) {
        return (p<size ? poem(p+1) + "\nThis is" + block(p) :"");
    }

    // returns (size-n) last lines of full couplet (with the first one truncated)
    public static String block(int b) {
        return (b<size ? " the " + scene[b] + block(b+1) : "");
    }

/******** Definitions for dynamic specialization *********/

    public String getText() {
        return all(size-numberOfCouplets);
    }

    final int numberOfCouplets;

    public Swift2(int numberOfCouplets) {
        this.numberOfCouplets = numberOfCouplets;
    }
}