MindTapV2.0 for Farrell's Java Programming with 2021 Updates, 9th Edition [Instant Access], 1 term
MindTapV2.0 for Farrell's Java Programming with 2021 Updates, 9th Edition [Instant Access], 1 term
9th Edition
ISBN: 9780357505540
Author: Farrell; Joyce
Publisher: Cengage Learning US
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
a database with multiple tables from attributes as shown above that are in 3NF, showing PK, non-key attributes, and FK for each table? Assume the tables are already in 1NF. [Hint: 3 tables will result after deducing 1NF -> 2NF -> 3NF]
If a new entity Order_Details is introduced, will it be a strong entity or weak entity? If it is a weak entity, then mention its type (ID or Non-ID, also Justify why)?
Which one of the 4 Entities mention in the diagram can have a recursive relationship? Order, Product, store, customer.
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:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Principles of Information Systems (MindTap Course...
Computer Science
ISBN:9781285867168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
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