MadLibs

MadLibs - System.out.println("Please choose a...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Class: ITP 109 * Lab#: 2 * Date modified: 01/29/2010 * Program description: this MadLibs program will ask the user to input different words (i.e. noun, verb, adjective) * and put them into a already created sentences to create an interesting story. */ import java.util.Scanner; i public class MadLibs { p public static void main(String[] args) { //declare variables String name1, name2, name3, name4, verb, adj; int num=0; Scanner keyboard = new Scanner(System.in); //Getting inputs from the user System.out.println("What's your name?"); name1 = keyboard.nextLine(); System.out.println("Please pick a predator Animal:"); name2 = keyboard.nextLine(); System.out.println("Please choose a another Animal:"); name3 = keyboard.nextLine(); System.out.println("Please choose a Musical Instrument:"); name4 = keyboard.nextLine(); System.out.println("Please choose a Verb in past tense:"); verb = keyboard.nextLine();
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.println("Please choose a Color:"); adj = keyboard.nextLine(); System.out.println("Please enter a Number"); num = keyboard.nextInt(); //Injecting the inputs from user into the created story String story = " Once upon a time, A " + name2 + " carried off a " + adj + " " + name3 + ".\n The " + name3 + " said: \"I know you are going to eat me, but before you do I " + "would like to hear you play the " + name4 + ".\"\n The " + name2 + " was so pleased at this that he took out his " + name4 + " and began to play." + "\n The shepherd and " + num + " dogs heard the sound, and they came running up and " + verb + " the " + name2 + " and the " + name3 + " was able to get back to the flock."; //printing the complete story after all inputs are injected by user System.out.println("Hello " + name1 + "!"); System.out.println(story); } }...
View Full Document

This note was uploaded on 03/15/2010 for the course ITP 109x taught by Professor Trinagregory during the Spring '08 term at USC.

Ask a homework question - tutors are online