PA1
James Madison University, Spring 2017 Semester
PA1: Madison Libs (Input and Output)

Due: Friday, Jan 20 at 11:59 PM
- -20% on Saturday, Jan 21 by 11:59 PM
- -40% on Sunday, Jan 22 by 11:59 PM
- Not accepted afterwards
Objectives
- Use a Scanner to read input of varying data types.
- Display output with print, println, and escape chars.
- Perform a simple calculation with multiple variables.
- Apply command-line tools to evaluate program style.
Honor Code
This assignment should be viewed as a take-home exam and must be completed individually. Your work must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 149/159, and the instructor. Copying work from another student or the Internet is an Honor Code violation and will be grounds for a reduced or failing grade in the course.
Getting Started
Mad Libs is a phrase-based word game invented by Leonard Stern and Roger Price—for more background information see this wikipedia page. The player is asked for several words or numbers, and then these words get plugged into a previously formulated sentence. The answers are often out of line with the phrase, so a humorous story is the product.
In this assignment, you will create a simple "Madison Lib" by taking input from the user (via the Scanner class) amd printing out the resulting sentence with your user input filling in the blanks. Here is a recent headline from a JMU end-of-year news announcement:
In __________(name)'s first season as head coach, JMU Football is heading
to __________(place) to compete for its second FCS National Championship
title. The Dukes were dominant all year, beating division rivals like
Richmond, Villanova, and William & Mary to _____(verb) the CAA
title and earn a No. __#__ seed in FCS postseason.
This ________(adverb) culminated in a historic __#__ - __#__ semifinal victory over
5-time reigning FCS champion NDSU in the ________(adjective) __________(place).
__________(same name) said, "I've always wanted to __________(same verb)
in the __________(same 2nd place)."
The Dukes are one win away from making history. In case you didn't
already know... game day is January 7th.
_____(action verb) Dukes!
See the example input and output below for the general idea. Create a new source file named MadisonLibs.java, and implement the entire program in the main method. Provide a meaningful Javadoc comment, including @author and @version tags, and remove unnecessary comments such as "add your code here." Write concise inline comments (using //) for each major section of the assignment described below (e.g., gathering input, doing calculations, displaying output). You should have these comments in place before writing any code!
Reading Input
Your program will need to read and store a variety of information while displaying the prompts as shown in the following example:
Enter a full name: John Q Public Enter a place: Paris, France Enter a present tense verb: roller blade Enter an adverb: stupidly Enter an adjective: blue Enter another place: fire station Enter an present tense action verb beginning with capital letter: Fall Enter a decimal number: 55.5 Enter a positive non-zero integer number: 45 Enter another positive or zero integer number: 75
Specifically:
- Read the full name (e.g., John Doe). Remember that some names have spaces in them.
- Read in a place (e.g., Lubbock, TX).
- Read in a present tense verb (e.g., run or swim).
- Read in an adverb (e.g., quickly).
- Read in an adjective (e.g., purple).
- Read in another place (e.g., library).
- Read in a present tense action verb beginning with a capital letter (e.g., Cry).
- Read in a decimal number (e.g., 5.75).
- Read in an integer number (e.g., 5). We will refer to this as your 'a' value for calculations. It will always be a positive whole number (greater than or equal to 1). Your output from this input will be a * 10 (i.e., 50).
- Read in another positive or zero integer value (e.g., 16). We will refer to this as your 'b' value for calculations. Your output from this input will be b / 5 (i.e., 3).
To get started, declare variables with meaningful names and types. Initialize a Scanner to handle the input, and use System.out.print to display each prompt exactly as shown. There is no need to handle invalid user input in this assignment.
Writing Output
Use the collected data to display the example Madison Lib exactly as shown. Given the input from the above section, the output would look like:
In John Q Public's first season as head coach, JMU Football is heading to Paris, France, to compete for its second FCS National Championship title. The Dukes were dominant all year, beating division rivals like Richmond, Villanova, and William & Mary to roller blade the CAA title and earn a No. 55.5 seed in FCS postseason. This stupidly culminated in a historic 450 - 15 semifinal victory over 5-time reigning FCS champion NDSU in the blue fire station. John Q Public said, "I've always wanted to roller blade in the fire station." The Dukes are one win away from making history. In case you didn't already know... game day is January 7th. Fall Dukes!
Note that you may see strange results like 55.50000000000001 (instead of 55.5). We will learn in the next assignment how to deal with this problem. For now, you must simply print all values as-is. Don't try to round, truncate, or format them to two decimal places.
Submission
Before uploading your MadisonLibs.java file to Webcat, be sure to complete the following steps carefully.
-
Run Checkstyle and eliminate ALL warnings about your code. Review and update comments as needed.
-
Make sure all variables are declared at the beginning of the main method, before any other statements.
Your submission will be graded using the following criteria:
Requirement | Points |
---|---|
PA1-A Quiz | 10 |
Javadoc and comments | 10 |
Variable names / types | 10 |
Prompts and data input | 20 |
Accurate calculations | 10 |
Output and formatting | 20 |
Passes Checkstyle | 20 |