
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...

Trending nowThis is a popular solution!

Chapter 2 Solutions
Java Programming, Loose-Leaf Version
- Ninth Edition Determine Zi, Zo and Av 20 V Zi + 1 ΜΩ 2 ΚΩ HH Z IDSS= 6MA Vp=-6V Yos = 40μS 20 and 47arrow_forwardWhat is the worst case time complexity of the following algorithm for i = 1 to x do for j = 2^((i-1)x) to 2^(in) do print(i,j)arrow_forwardProve for each pair of expression f(n) and g(n) whether f(n) is big O, little o Ω,ω or Θ of g(n). For each case it is possible that more than one of these conditions is satisfied:1. f(n) =log(n2^n), g(n) = log(sqrt(n)2^(n^2))2. f(n) =nsqrt(n) +log(n^n), g(n) =n + sqrt(n)lognarrow_forward
- I need to make a parallel version of this sequential codearrow_forwardI need to make a parallel version of this sequential code.arrow_forwardBenefits of using arrays as instance variables: What are the advantages of incorporating arrays as instance variables within a class? Initializing and managing arrays: How do you initialize and manage arrays within class constructors and mutators (setters)? Example of using arrays as instance variables: Share an example where you have used arrays as instance variables and discuss its application in a real-world scenario. Common mistakes with arrays as instance variables: What are some common mistakes to avoid when working with arrays as instance variables? Information hiding violations: What is the potential violation of information hiding when using arrays as instance variables? How can this be resolved?arrow_forward
- Do you think that computers should replace teachers? Give three references with your answer.arrow_forwardIs online learning or face to face learning better to teach students around the around the world? Give reasons for your answer and provide two references with your response. What are benefits of both online learning and face to face learning ? Give two references with your answer. How does online learning and face to face learning affects students around the world? Give two references with your answer.arrow_forwardExplain Five reasons if computers should replace teachers. Provide three references with your answer. List three advantages and three disadvantages face to face learning and online learning may have on children. Provide two references with your answer.arrow_forward
- You were requested to design IP addresses for the following network using the address block 10.10.10.0/24. Specify an address and net mask for each network and router interfacearrow_forwardFor the following network, propose routing tables in each of the routers R1 to R5arrow_forwardFor the following network, propose routing tables in each of the routers R1 to R5arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Principles of Information Systems (MindTap Course...Computer ScienceISBN:9781285867168Author:Ralph Stair, George ReynoldsPublisher:Cengage LearningSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning




