CS139 Algorithm Development


Software Requirements Specification

Programming Assignment 3

Mad Lib

Due Friday, October 22 by 5pm


Introduction

Purpose: This program will play a game with the user.  The user will provide a series of words and numbers and the computer will use those words to produce a Mad lib style story.  Mad libs consist of a text with blanks.  The player is asked for a specific series of words and the reader fills those into the story for the blanks.  See the web site:  http://www.eduplace.com/tales/ for some examples. 

Objectives - At the conclusion of this exercise the student will demonstrate that they can:

Deadlines

Prerequisites


You have covered the material in Chapter 2, 3, and 5 of Gaddis.  You will want to reference Chapter 10 on String methods as you work the PA.

Starter Files

MadLibDriver.java

MadLib.java

Program Behavior

Your application must do these things:

  1. Your program will prompt for and read five input values.  These are:
    1. A person's name (String)
    2. A person's gender (String)
    3. A color (String)
    4. An animal (String)
    5. A number (int)
    6. A time (String)
    7. The name of a sound (String)
    8. And an action verb (String)
  2. Your program must display the story (specified below) with the missing elements filled in by the input or calculated values.
  3. All output must be properly formatted.

Output

  1. Output the heading,  "Welcome to the CS139 Mad Lib game" followed by the newline character.
  2. Output a blank line.
  3. Prompt for the input values. Output the newline character after reading the each input value and before the next prompt. Note: your input will be on the same line as the prompt.
    1. Your first input prompt must be the String, "Enter a person's name: "
    2. Your second input prompt must be the String, "Enter the person's gender: " 
    3. Your third input prompt must be the String, "Enter your favorite color: "
    4. Your fourth input prompt must be the String, "Enter an unusual animal: "
    5. Your fifth input prompt must be the int, "Enter a whole number between 1 and 13: "
    6. Your sixth intput prompt must be the String, "Enter a time: "
    7. Your seventh input prompt must be the String, "Enter a sound: "
    8. Your eighth prompt must be the String, "Enter a past tense action verb: "
  4. After reading all of the input values, output a blank line then the story as follows:  The values in square brackets [] are the substitutions.  The story must be formatted as shown. NOTE: you must have newline characters after each of the lines shown here. In other words, your story should have a title, a new blank line, and then the body which is exactly 5 lines long.
[Person name(1)]'s Weird Halloween Adventure

[Person name(1)] was a [girl/boy (based on gender 2)] of [whole number (3)] year[s (4)].
[She/He (based on gender)(5)] decided to go Trick or Treating dressed as a[n (6)] [color(7)] [unusual animal(8)].
At [time(9)], [Person name(1)] heard a loud [sound(10)] behind [him/her(11)]. [She/He(5)] turned and saw
[number (12)] real [unusual animal(8) [s](13)] following [him/her(14)]. [Person name(1)] was so scared that
[she/he(15)] [verb(16)] all the way home.

Example

Gerry's Weird Halloween Adventure

Gerry was a boy of 12 years.
He decided to go Trick or Treating dressed as an orange oyster.
At 8pm, Gerry heard a loud crunch behind him. He turned and saw
twelve real oysters following him. Gerry was so scared that
he jumped all the way home.


Explanations for numbered items above:

1 - Person name - Just use whatever is typed in.
2 - girl/boy - You should have a girlBoy method which takes in a char representing the gender and returns the word "girl" or "boy" based on whether an F or M is typed in.  See error checking below.
3 - Whole number - Use the number as entered by the user (altered by the error checking described below for the number).
4 - s - If the number entered is 1, then you leave the word year alone. If the number entered is greater than one, you use years.
5 - He/She - If the gender is M then He, F then She.
6 - A [n] - If the color starts with a vowel (like orange or emerald), you use the determinant an otherwise you use a. 
7 - color - Use whatever the user types for this one.
8 - unusual animal - Use whatever the user types in.
9 - time - Use whatever the user types in.
10 - sound - Use whatever the user types in.
11 - him/her - If the gender is M then him, F then her.
12 - Use the words for the number. So if the number were 5, use five.
13 - If the number is greater than one, you need to make the animal name plural.  So for example if the animal was a whale, then you would use whales. The only rules you need to follow for plurals are:
  1. If the name ends in an s, add es. (Example - rhinocerous, rhinocerouses)
  2. If the name ends in ey, just add s. (Example - monkey, monkeys)
  3. Otherwise if the name ends in y, change the y to ies (Example - butterfly, butterflies)
  4. All other names will have an s added to the name (Examples, dog-dogs, moose-mooses)

Inputs and error checking

  1. Gender must be entered as M, m, F, or f. Anything else constitutes an error. You should immediately output the error message, "You entered %s. Using \"F\"", where the substitution will be the value that they entered. You should assume female if the gender is entered incorrectly.
  2. If something other than a number is entered where we are asking for a whole number, you should immediately output the error message, "You entered %s. Using 1", where the substitution will be the value that they entered. You should assume 1 if the number is entered incorrectly.
  3. If a number is entered that is outside of the range 1 to 13, you should simply use 1 if the number is less than 1 and 13 if the number is greater than 13.
  4. All other values can be used as is.

Additional Program Requirements

  1. You must have a story driver file named MadLibDriver.java. This will be given to you. It will create a MadLib object and call the tellStory method. tellStory will do all of the input and output for the story.
  2. You must have methods to handle Item # 2, 5, 6, 11, 12, and 13 from the explanation list above.
  3. You must have a method to check if the number entered is outside of the range 1 to 13. The method should return the number that we will use for the story.
  4. Your program must include an acknowledgement section acknowledging help received from TAs or reference sources. You do not need to reference receiving help from the instructor.
  5. If you received no help your acknowledgement section should have a statement to that effect.
  6. Your program must conform to standard Java programming standards and the additional standards for this class. See the Style Guide for your class.

Suggested Approach

  1. Start with the tellStory method.
  2. Create a variable for each of the substitutions in the story above.
  3. Initialize each to a fixed value for the particular story you want to build.
  4. Create the output of the story, substituting your variables declared in step 1 where appropriate.
  5. TEST! Look for spacing, punctuation types of problems.
  6. For each of the variables in the list that is just using what the user enters, create the prompts and reads to fill in those values.
  7. TEST! Look for spacing, punctuation problems.  Remove the hardcoded initialization.
  8. For each other value, create a new variables as needed. For example, to choose He/She, you need to have a variable for gender and a variable for the He/She word chosen.
    1. If required, create the new prompt and read lines.
    2. Create the method to do the transformation of the value.
    3. TEST! the method in the story.
  9. As it is the most complex, save the plural method for last.
  10. You are welcome to have a friend help you test the final product before submit, as long as that person is not in any of the CS139 classes.

Honor Code

This work must conform to the JMU Honor Code and the specific requirements of this class. NO help may be provided by another student to another student. Authorized help is limited to your textbook, the TA’s for any CS139 section, and the professor for your section. See collaboration policy.

Grading

HINTS