Fund. CS II (CS152 2005F)

Homework 1: Mad-Libs, Simplified

Assigned: Wednesday, 7 September 2005
Due: 11:00 a.m., Wednesday, 14 September 2005

Summary: In this assignment, you will implement a simple version of the game Mad Libs.

Purpose: To give you an opportunity to explore issues of input, output, and strings in Java.



You may be familiar with the game Mad Libs. In this game of two or more players, one player serves as the questioner and the remaining players provide answers. The questioner works from a text in which certain words are missing and asks the players to submit words for those that are missing. The only detail that the questioner provides is the part of speech (or other description of the expected word). The questioner then reads the resulting text.

Consider the following text:

John likes to _verb_ with Java
because he thinks that Java is _adjective_.
When things go well, John is _adjective_.
When things go badly, John yells "_exclamation_!"

In this case, the questioner would ask for a verb, two adjectives, and an exclamation. If the players provided the words sleep, green, stupid, and foo, the questioner would then read

John likes to sleep with Java
because he thinks that Java is green.
When things go well, John is stupid.
When things go badly, John yells "foo!"

The Assignment

Write a program the serves the role of the questioner in Mad Libs. Your program should

You can assume that the template file contains exactly four lines, and that each line contains exactly one thing to fill in. I've written a template that matches these specifications for the sample in this assignment and another template.

You should also create at least two Mad Libs templates that meet those criteria.

A Sample Session

% ji rebelsky.madlibs.MadLibs
Please enter the name of the template file: johnjava.txt
Please enter the name of the result file: jj1.txt
Please enter a(n) verb: walk
Please enter a(n) adjective: superfluous
Please enter a(n) adjective: incredible
Please enter a(n) exclamation: wicked

Here is your story ...

  John likes to walk with Java 
  because he thinks that Java is superfluous.
  When things go well, John is incredible.
  When things go badly, John yells "wicked!"

Submitting Your Work

When you are satisfied with your work, you should submit it to me. Please put the program and the templates in the directory username.madlibs and make sure that I have access to all files in that directory. Then send me an email noting that you have made the files available to me.


When you ask questions, I'll try to put the answers here.



Wednesday, 7 September 2005 [Samuel A. Rebelsky]

Monday, 12 September 2005 [Samuel A. Rebelsky]


Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue Dec 6 09:47:02 2005.
The source to the document was last modified on Mon Sep 12 15:27:01 2005.
This document may be found at

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Samuel A. Rebelsky,