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
Packages are a common way to create products that consist of other products. For example, any fast food chain creates "menus" using a main course, a side dish, and a drink. Typically, the main course is a hamburger, the side dish is french fries, and the drink is a soft drink (Cola, Buttermilk, and the like). Menus are also given a name to distinguish them. You are asked to create such menus, but the price of these menus should not be the same as the items on the menu. It should receive a 10 percent discount on the main line, 20 percent on the side, and 50 percent on the drink. In the main section, list the names of their menus and the food served. There should be two menus consisting of a main course, a side dish and a drink. Menus should be listed as items on the menu and their prices. After listing the menus, the products should be listed according to their name and price. WRITE JAVA CODE ACCORDING TO THIS
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 number maze is an n × n grid of positive integers. A token starts in the upper left corner; your goal is to move the token to the lower-right corner. On each turn, you are allowed to move the token up, down, left, or right; the distance you may move the token is determined by the number on its current square. For example, if the token is on a square labeled 3, then you may move the token three steps up, three steps down, three steps left, or three steps right. However, you are never allowed to move the token off the edge of the board. 6 3574 5 315 3 283 35 74 6 53 15 1 4 2 8 3 1 4 4 5 7 2 3 4 5 7 2 3 3 1 3 2★ 3 KT3 A 5 × 5 maze that can be solved in eight moves In this problem, you will design and analyze an efficient algorithm that either returns the minimum number of moves required to solve a given number maze, or correctly reports that the maze has no solution. Describe the solution to this problem at a high level, justify why it works, write down the pseudocode for your algorithm…
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