CIT 590 Assignment 10: Mad Libs
Fall 2015, David Matuszek

Purpose of this assignment

  • To introduce you to using the Java API.
  • To familiarize you with ArrayLists.
  • To give you more experience with String processing.
  • To introduce Java I/O.
  • General idea of the assignment

    Create a "Mad Lib." If you aren't familiar with this silly children's game, take a look at Wacky Web Tales (http://www.eduplace.com/tales/) before reading further.

    Details

    Create a text file containing a story, with "blanks" (actually, terms in brackets) to be filled in. Here is an example, "The Best Day of My Whole Life," from the Wacky Web Tales site mentioned above. I chose this one because it has relatively few blanks to fill in.

    One day I was walking to school when I found a wallet
    on the ground. I picked it up. It had no ID in it, so
    I decided to keep it. It had [large number] bucks in it.
    Like any kid, I was [adjective].

    The first thing I did was go to the police to check if
    anybody lost it. The man said he would keep it in case.

    I was, of course, [feeling]. Then after a few days of
    being happy, I got a call from the person who lost the
    wallet. He said he was really [feeling] with me for being
    honest. He was so grateful that he sent my family and me
    on a trip to [foreign country].

    It was the most [adjective] day of my life!

    Save your (original) story on a text file, not a formatted file such as MSWord produces. Name your file story.txt. Try to make it amusing!

    Your program should read this file, one line at a time, into an ArrayList. Then it should search each line in the ArrayList for any text within brackets, ask the user for a word or words of that kind (don't show the brackets), and replace them in the text. For each question, use "a" before a consonant, "an" before a vowel; for example, if you are asking for an adjective, ask for an adjective, not for a adjective. Consider a-e-i-o-u (uppercase or lowercase) to be vowels, but not y.

    Fill in the blanks to get an exciting story!
    Enter a large number:
    (User types something in for each of these)
    Enter an adjective:
    Enter a feeling:
    Enter a feeling:
    Enter a foreign country:
    Enter an adjective:

    When everything has been filled in, print the story.

    ArrayLists are objects that you can use like arrays (though you can't use any of the special array syntax, such as a[i]). The big advantage of an ArrayList, compared to an array, is that you don't need to know in advance how big to make it. ArrayLists are objects, so you can look up methods for working with them in the Java 7 API or Java 8 API. To explore these methods, choose the java.util package, then in the lower panel choose the ArrayList class. (Note: Many of these methods use angle brackets, such as <E> or <? extends E>. Don't worry if you don't understand everything you see--we'll get to the angle bracket stuff later.

    You can assume:

    You can not assume:

    Name your class MadLib and your package madLib. Your main method should call a constructor to create a new MadLib object. The Madlib object should contain a readFile method to read in a new story template from a file, and a play() method to interact with the user. Have an ask method that gets a word or phrase from the user. Check to make sure that the user actually typed something--insist on getting a response to every question.. You may write as many additional methods as you need; in particular, if you find yourself repeating code, you should try to put that code into a method.

    As much as possible, have separate methods for doing computation (mostly string manipulation) and for doing I/O. Unit test the former.

    Due date

    Zip your entire package and submit it to Canvas by 6am Wednesday, November 4.