/**--------------------------------------------- * Program 1 - Adlibs * This program takes user input and * plugs it into an existing story, * giving (sometimes) funny results. * * Class: CS 102, Fall 2008 * Lab: Billie Joe Armstrong, Wed. 6:00 AM * System: BlueJ 2.1.1, jsdk 1.5, Windows XP * * @author Dale Reed * @version August 27, 2008 * * Running the program looks like: Author: Dale Reed Program: #1, Adlibs TA: Englebert Humberdink, T 4-5 Aug 27, 2008 Supply some words that will be inserted into a story. Please enter 4 nouns (a person, place, or thing, e.g. computer), one per line: aardvark frisbee pogo stick boomerang Please enter 4 adjectives (describes a noun, e.g. enormous), one per line: gigantic diminuitive obscure elegant Please enter 5 verbs (an action, e.g. run), one per line: dive fly swallow rejoice cough Please enter 1 adverb (describes a verb, e.g. quickly), one per line: slowly Please enter 2 numerical values (e.g. 3, or 21), one per line: 4 8 This semester the most gigantic thing happened in class. when I walked in there were 4 students who began to dive and fly. "Where's the Prof?" I asked slowly. "He slipped on a aardvark and began to swallow", they said. "Paramedics used a frisbee to carry him out. He gave us a diminuitive obscure assignment due in 8 days. We have to write a elegant program to rejoice a pogo stick by a boomerang and then cough it to turn it in." That's when I switched majors. Exiting Program... * ---------------------------------------------- */ // Import libraries needed by the program import java.util.Scanner; // used for console input // Declare the class public class Adlibs { // Fields that can be accessed anywhere in the class go here Scanner keyboard = new Scanner( System.in); // used to read user input //---------------------------------------------------------------------------------------- // main() - startup main loop. It is necessary to create an instance of this class // and then call a method from that instance, otherwise there are all kinds // of error messages having to do with non-static objects (e.g. keyboard) // being called from a static context (e.g. main). By creating the instance // and *then* using keyboard, it is not longer being called from a static // context. Don't worry about understanding all this right now. public static void main(String[] args) { // create an instance of this class Adlibs theAdlibsInstance = new Adlibs(); // call a non-static method to do everything else theAdlibsInstance.mainLoop(); } //---------------------------------------------------------------------------------------- // mainLoop() - display identifying information and run main loop. // In your program, you will only add code inside this method. You don't need to // change anything above except for the comments at the top of the program. // void mainLoop() { // Display identifying information System.out.println( "Author: Dale Reed \n" + "Program: #1, Adlibs \n" + "TA: Englebert Humberdink, T 4-5 \n"+ "Aug 27, 2008"); System.out.println(); // Display game instructions System.out.println( "Supply some words that will be inserted into a story. \n"); // declare variables // declare variables for the adjectives String adjective1 = ""; String adjective2 = ""; String adjective3 = ""; String adjective4 = ""; // declare variables for the adverbs String adverb1 = ""; // declare variables for the nouns String noun1 = ""; String noun2 = ""; String noun3 = ""; String noun4 = ""; // declare variables for the numbers int number1 = 0; int number2 = 0; // declare variables for the verbs String verb1 = ""; String verb2 = ""; String verb3 = ""; String verb4 = ""; String verb5 = ""; // prompt for and get the words from the user System.out.print("Please enter 4 nouns (a person, place, or thing, e.g. computer), one per line: \n"); noun1 = keyboard.nextLine(); // read user input noun2 = keyboard.nextLine(); // read user input noun3 = keyboard.nextLine(); // read user input noun4 = keyboard.nextLine(); // read user input System.out.print("Please enter 4 adjectives (describes a noun, e.g. enormous), one per line: \n"); adjective1 = keyboard.nextLine(); // read user input adjective2 = keyboard.nextLine(); // read user input adjective3 = keyboard.nextLine(); // read user input adjective4 = keyboard.nextLine(); // read user input System.out.print("Please enter 5 verbs (an action, e.g. run), one per line: \n"); verb1 = keyboard.nextLine(); // read user input verb2 = keyboard.nextLine(); // read user input verb3 = keyboard.nextLine(); // read user input verb4 = keyboard.nextLine(); // read user input verb5 = keyboard.nextLine(); // read user input System.out.print("Please enter 1 adverb (describes a verb, e.g. quickly), one per line: \n"); adverb1 = keyboard.nextLine(); // read user input System.out.print("Please enter 2 numerical values (e.g. 3, or 21), one per line: \n"); number1 = keyboard.nextInt(); // read user input number2 = keyboard.nextInt(); // read user input // leave some blank lines for the story System.out.println(" \n\n\n"); // display the story System.out.println(" This semester the most " + adjective1 + " thing happened in class. "); System.out.println("when I walked in there were " + number1 + " students who began to " + verb1); System.out.println("and " + verb2 + ". "); System.out.println(" \"Where's the Prof?\" I asked " + adverb1 + "."); System.out.println(" \"He slipped on a " + noun1 + " and began to " + verb3 + "\", they said."); System.out.println("\"Paramedics used a " + noun2 + " to carry him out. He gave us a " + adjective2 + " "); System.out.println(adjective3 + " assignment due in " + number2 + " days. We have to write a "); System.out.println(adjective4 + " program to " + verb4 + " a " + noun3 + " by a " + noun4 + " and then "); System.out.println(verb5 + " it to turn it in.\" "); System.out.println(" That's when I switched majors."); System.out.println(); System.out.println("Exiting Program..."); }//end method mainLoop() }//end class Morph