Advertisement
teleias

A Sleepy Story

Sep 4th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.00 KB | None | 0 0
  1. //Here's my (Austin Takechi's) personal answer to "how to generate the 'a sleepy story'" question.
  2. // The tail end could be made more recursive I think, but whatever.
  3. public class csc135 {
  4.     public static String paragraph = "So %s mother said:\nOnce upon a time there was a %s,\na %s with %s.\n%s%s\n%s";
  5.     public static void main(String[] args)
  6.     {
  7.         System.out.println(foo(0));
  8.         //doIt(0);
  9.     }
  10.     //public static String[] creatures = new String[]{"a", "b", "c"};
  11.     public static void doIt(int layer)
  12.     {
  13.         System.out.println("Once upon a time, there was a "+creatures[layer]);
  14.         if(layer < 3-1)
  15.             doIt(layer+1);
  16.         System.out.println("so was the "+creatures[layer]);
  17.     }
  18.     public static String[] pronouns = new String[]{"", "her", "his", "his", "her", "her", "her"};
  19.     public static String[] creatures = new String[]{"", "giraffe", "fox", "elephant", "puppy", "field mouse", "pony"};
  20.     public static String[] adjectives = new String[]{"", "little", "little red", "little gray", "fluffy black", "little gray", "little brown"};
  21.     public static String[] withAs = new String[]{"", "a long, long neck", "a big, bushy tail", "a big, big trunk", "floppy ears", "a long, skinny tail", "a thick black mane"};
  22.     public static String[] notSleepys = new String[]{"", "It was time to go to sleep, but he was not sleepy.\n", "It was time to go to sleep,\n", "It was time to go to sleep,\n", "It was time to go to sleep,\n", "", ""};
  23.     public static String[] penultimates = new String[]{"", "Well, maybe he was a tiny bit sleepy.", "and he was beginning to be very sleepy.", "and she was beginning to be just a little bit sleepy.", "and she was a sleepy puppy.", "She was a very sleepy little mouse.", "He was a sleepy, sleepy little pony."};
  24.     public static String saidToMother = ", "+'"'+"Tell me a story."+'"';
  25.     public static String[] ultimates = new String[]{"", "She said to her mother"+saidToMother, "He said to his mother"+saidToMother, "He said to his mother"+saidToMother, "She said to her mother"+saidToMother, "She said to her mother"+saidToMother, "He yawned. Then he said to his mother, \"Tell....me....a....story.\""};
  26.     public static String[] backUps = new String[]{"And so was the little girl, all cuddled up under her red blanket.\nAll fast asleep.\nGood night!", "So was the little giraffe with the long, long neck.", "So was the little red fox with the big bushy tail.", "So was the little gray elephant with the big, big trunk.", "So was the fluffy black puppy with the floppy ears.", "So was the little gray field mouse with the long skinny tail.", ""};
  27.     public static String foo(int layer)
  28.     {
  29.         if(layer > 6)
  30.         {
  31.             return "";
  32.         }
  33.        
  34.         String result = "";
  35.        
  36.         String pronoun = ""; //her/his
  37.         String creature = ""; //giraffe
  38.         String adjective = ""; //red fox
  39.         String withA = ""; //big big trunk
  40.         String notSleepy = ""; //but he was not sleepy.
  41.         String penultimate = ""; //Well, maybe he was a tiny bit sleepy.
  42.         String ultimate = ""; //She said to her mother "Tell me a story."
  43.         String backUp = ""; //So was the little giraffe with the long, long neck.
  44.         if(layer == 0)
  45.         {
  46.             result = "Once there was a little girl.\nIt was time to go to sleep, but she was not sleepy.\nWell, maybe she was just a tiny bit sleepy,\nShe hopped into bed and covered herself\nup to her chin with her big red blanket.\nShe said to her mother, "+'"'+"Tell me a story."+'"'+"\n";
  47.         }
  48.         else
  49.         {
  50.             pronoun = pronouns[layer];
  51.             creature = creatures[layer];
  52.             adjective = adjectives[layer];
  53.             withA = withAs[layer];
  54.             notSleepy = notSleepys[layer];
  55.             penultimate = penultimates[layer];
  56.             ultimate = ultimates[layer]+"\n";
  57.             result = String.format(paragraph, pronoun, creature, adjective+" "+creature, withA, notSleepy, penultimate, ultimate);         
  58.         }
  59.         backUp = backUps[layer];
  60.        
  61.         result += "\n"+foo(layer+1);
  62.         if(layer==6)
  63.         {
  64.             result = result + ("So his mother said:\nOnce upon a time... \nBut the little brown pony did not hear.  He was fast asleep.\n\n");
  65.         }
  66.         else
  67.         {
  68.             result = result + backUp +"\n";
  69.         }
  70.        
  71.         return result;
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement