Java Programming
Java Programming
9th Edition
ISBN: 9780357238530
Author: Joyce Farrell
Publisher: Cengage Limited
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
(using R)The iris data set in R gives the measurements in centimeters of the variables sepal length and width andpetal length and width, respectively, for 50 flowers from each of 3 species of iris, setosa, versicolor, andvirginica. Use the iris data set and the t.test function, test if the mean of pepal length of iris flowers isgreater than the mean of sepal length.The iris data set in R gives the measurements in centimeters of the variables sepal length and width andpetal length and width, respectively, for 50 flowers from each of 3 species of iris, setosa, versicolor, andvirginica. Use the iris data set and the t.test function, test if the mean of pepal length of iris flowers isgreater than the mean of sepal length.
Recognizing the Use of Steganography in Forensic Evidence (4e)Digital Forensics, Investigation, and Response, Fourth Edition - Lab 02
Write a Java Program to manage student information of a university. The Javaprogram does the following steps:a) The program must use single-dimensional arrays to store the studentinformation such as Student ID, Name and Major.b) The program asks the user to provide the number of students.c) The program asks the user to enter the Student IDs for the number of studentsand stores them.d) The program asks the user to enter the corresponding names for the numberof students and stores them.e) The program then asks the user to provide the corresponding major for thestudents and stores them.f) The program then should display the following options:1. ID Search2. Major Enrollment3. Exitg) On selecting option 1, the user can search for a student using Student ID. Theprogram asks the user to enter a Student ID. It then should print thecorresponding student’s details such as Name and Major if the user providedStudent ID number is present in the stored data. If the user’s Student IDnumber does not…
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