Downloadable version: Madlib.java

//*******************************************************************
//
//   File:    Madlib.java
//   Subject: CS-112 AS1 Solutions
//   Date:    January 31, 2001
//   Author:  Gabriel Loh
//   Classes: Madlib
//
//*******************************************************************

/* No imports.  Assuming that Keyboard.class is in the current
   directory. */

//===================================================================
// CLASS Madlib queries the user for some words, and then outputs
// a side-splitting mad-lib.
//===================================================================
public class Madlib
{

//===================================================================
// THE MAIN METHOD
//===================================================================
  public static void main(String args[])
  {
    /* These are the variables that will be assigned the user's input.
       adj is an adjective, ptverb is a past-tense verb, noun is a noun. */
    String adj, ptverb, noun;

    /* Each part of speech uses the print method of System.out to
       issue a prompt to the user, and then uses the readString
       method from the Keyboard class to read in the user's input. */

    // Get the adjective
    System.out.print("Adjective: ");
    adj = Keyboard.readString();

    // Get the past tense ptverb
    System.out.print("Verb (past tense): ");
    ptverb = Keyboard.readString();

    // Get the noun
    System.out.print("Noun: ");
    noun = Keyboard.readString();

    // Use string concatenation to print out the completed mad-lib
    System.out.println("The "+adj+" professor "+ptverb
                +" my "+noun+" and I've never recovered.");

    /* I could have also used several print statements in a row to
       print out the different parts separately. */

  } // end of method main

} // end of class Madlib