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:
- Use an editor to create a java source file from scratch.
- Write java code to create an attractive user interface.
- Write java code to perform basic arithmetic calculations and
String manipulation.
- Use the proper
next????
method from the Scanner
class.
- Use the
NumberFormat
or DecimalFormat
class to properly format currency values.
- Create methods in a class and use them in a different class
- Use decision structures to manipulate data and prevent errors.
- Do everything necessary to create, debug, and run a java
program.
- Use comments to delineate each section of the program.
- Adhere to a Style Guide.
- READ AND FOLLOW DIRECTIONS!!!!!
Deadlines
- Submit: October 22 by 5pm into the stu submit system.
- Report: October 25 by the beginning of class. A 20
points/day late penalty will apply for each of the 2 deadlines. If the
submit is late, the report is due the next class or lab session day
after successful submission. Programs will not be accepted after
7 days late.
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:
- Your program will prompt for and read five input values.
These are:
- A person's name (String)
- A person's gender (String)
- A color (String)
- An animal (String)
- A number (int)
- A time (String)
- The name of a sound (String)
- And an action verb (String)
- Your program must display the story (specified below) with the
missing elements filled in by the input or calculated values.
- All output must be properly formatted.
Output
- Output the heading,
"Welcome to the CS139 Mad Lib game"
followed
by the newline character.
- Output a blank line.
- 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.
- Your first input prompt must be the String, "Enter a person's name: "
- Your second input prompt must be the String, "Enter the person's gender: "
- Your third input prompt must be the String, "Enter your favorite color: "
- Your fourth input prompt must be the String, "Enter an unusual animal: "
- Your fifth input prompt must be the int, "Enter a whole number between 1 and 13: "
- Your sixth intput prompt must be the String, "Enter a time: "
- Your seventh input prompt must be the String, "Enter a sound: "
- Your eighth prompt must be the String,
"Enter a past tense action verb: "
- 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:
- If the name ends in an s, add es. (Example - rhinocerous,
rhinocerouses)
- If the name ends in ey, just add s. (Example - monkey, monkeys)
- Otherwise if the name ends in y, change the y to ies (Example -
butterfly, butterflies)
- All other names will have an s added to the name (Examples,
dog-dogs, moose-mooses)
Inputs and error checking
- 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.
- 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.
- 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.
- All other values can be used as is.
Additional Program Requirements
- 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.
- You must have methods to handle Item # 2, 5, 6, 11, 12, and 13
from the explanation list above.
- 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.
- 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.
- If you received no help your acknowledgement section should
have
a statement to that effect.
- 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
- Start with the tellStory method.
- Create a variable for each of the substitutions in the story
above.
- Initialize each to a fixed value for the particular story you
want to build.
- Create the output of the story, substituting your variables
declared in step 1 where appropriate.
- TEST! Look for spacing, punctuation types of problems.
- 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.
- TEST! Look for spacing, punctuation problems. Remove the
hardcoded initialization.
- 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.
- If required, create the new prompt and read lines.
- Create the method to do the transformation of the value.
- TEST! the method in the story.
- As it is the most complex, save the plural method for last.
- 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
- Your program will be evaluated both by its correctness and
conformance to the required elements.
- You will achieve a grade of 70 for a program that runs
correctly
and produces exactly the required output in the required format.
- You will achieve 10 points for submitting your test data.
- The remainder (20) will be based on your conformance to the
Style
and other requirements of the assignment. Review the Style
Guide before
submitting your program and the grade sheet which is produced by the
submit system.
- All grades will be based on 100 points.
- You may submit any number of times. The only one I will count
is
the one that corresponds to the hardcopy report that you turn in.
- The hardcopy that you turn in will be the formatted version
that
I will check. Make sure it has no line wraps or other spacing
issues.
- Successfully submitted programs that are late will be graded,
then the point penalty assessed for each day late.
- For
submissions after:
- Oct. 22 - 5 points
- Oct. 24 - 15 points
- Oct. 25 - 25 points
- Oct. 26 - 35 points
- Oct 27 - 45 points
- Oct 28 - 100 points
HINTS
- Begin early.
This program is fairly long and you will want to work on it bit by bit.
Students run into trouble by waiting too long
to start the program.
- Understand the problem at hand. Make sure that you follow
the requirements precisely. Don't add additional "flourishes".
You will be downgraded.
- Design a top level algorithm. Don't worry as you are
designing that you might not yet know how to do input or format output.
Design as if you have those tools. You will get them before
it is due.
- Design your substeps, at least the ones you can do now.
Fill in the others as we cover material in class or you study it
in your book.
- Your top level algorithm can be used as step documentation in
your program. Start there.