EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Videos

Expert Solution & Answer
100%
Book Icon
Chapter 2, Problem 1GZ

Explanation of Solution

Program code:

MadLib.java

//import the required packages

import java.io.*;

//define a class MadLib

class MadLib

{

//define a method intro()

private static void intro()

{

//create a string variable and initialize it

String msg = "This is a Mad-Lib game. I will prompt " +

"you for five words.\n";

//print the string

System.out.print(msg);

}

//define a method getInput()

private static String getInput(String msg) throws IOException

{

//create the object of BufferReader

BufferedReader stdin;

//initialize the object

stdin = new BufferedReader(new InputStreamReader(System.in));

//print the string msg

System.out.print(msg);

//return the line readed

return stdin.readLine();

}

//define a method printOutput

private static void printOutput (String noun1, String adverb, String noun2, String pronoun, String adj)

{

//create a string output and set the value

String output = "\nThree blind " + noun1 + ", \nThree blind " + noun1 + ", \nsee " + adverb +

     " they run!" + "\nsee " + adverb + " they run!\nThey all ran after the farmer's " + noun2 +

      "\nWho cut off their tails,\nWith a carving knife.\nDid you ever see " +

        pronoun + " a thing in your life,\nAs three " + adj + " mice.";

//print output

System.out.println(output);

}

//define a main() method

public static void main(String[] args) throws IOException

{

//call the method intro()

intro();

//get the value for noun1

String noun1 = getInput("Enter a noun : ");

//get the value for adverb

String adverb = getInput("Enter a adverb : ");

//get the value for noun2

String noun2 = getInput("Enter a another noun : ");

//get the value for pronoun

String pronoun = getInput("Enter a pronoun : ");

//get the value for adj

String adj = getInput("Enter an adjective : ");

//print the accepted values

printOutput(noun1, adverb, noun2, pronoun, adj);

}

}

Explanation:

The above snippet of code is used get the noun, adverb, pronoun and adjective from the user and creates the sentences using it...

Blurred answer
Students have asked these similar questions
Mad Libs is a game where the player selects words based on part of speech that are then used to fill in the missing  words for a story. For instance, if I ask you for a noun, past‐tense verb, and another noun, you might say “CAT”,  “BOUGHT”, “ZEBRA”. Those could be filled in to the story: “The   some playdough and gave it  to the ”, and you would end up with The cat bought some playdough and gave it to the zebra. Write a program in C# (and a story) to do a Mad Lib. Your story should be original… not something you find on the Internet. You need to read in  a minimum of 10 words to add to your story. Once the words are entered, display the story on the console. Here’s an  online one you can play for some inspiration: http://www.redkid.net/cgi‐bin/madlibs/caroftheyear.pl (but not TOO  MUCH inspiration ‐‐ do not copy one of these!)
Tentaizu is a classic Japanese game that consists of a 7x7 board of which 10 of those 49 slots are "stars". The objective of the game is to determine the position of these stars. To help with identifying the correct position, some slots contain hints in the form of numbers. These hints work like the number hints in minesweeper in the sense that it identifies how many stars are adjacent to the slot. The range of values are from 0 (no stars) to 8 (fully surrounded by stars). A Tentaizu puzzle contains only these number hints. Much like other puzzle games like sudoku, there is only one combination of star positions that is described by the puzzle. Your task is to create a solver function for a given Tentaizu puzzle using python. This function should be able to recursively solve the puzzle. Define a function "solve" with the input variable being a 7x7 list representing the Tentaizu puzzle. The return value should be a list of tuples containing the correct coordinates of the 10 stars. If…
A "mad-lib" is a fill-in-the blank game. One player writes a short story in which some words are replacedby blanks. For each word that is removed, the appropriate part of speech is noted: e.g. noun (person/-place/thing), adjective (word that describes a noun), verb (an action, e.g. eat), adverb (modifies a verb, e.g.quickly). Then, before reading the story, the story-writer asks the other player to write down a word of theappropriate part of speech for each blank without knowing the context in which it will be used. In this way,a humorous (sometimes) or non-sensical (usually) story is created.Write your own mad-lib. It must have at least three blanks in it. Now write a Python program that doesthe following:- Using the input() syntax (see the section "Reading Strings from the Keyboard" from the course read-ings) for reading strings from the console, prompt the user to enter a word of the appropriate part ofspeech for each blank in your program. Have a different, appropriately named…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Memory Management Tutorial in Java | Java Stack vs Heap | Java Training | Edureka; Author: edureka!;https://www.youtube.com/watch?v=fM8yj93X80s;License: Standard YouTube License, CC-BY