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
MindTapV2.0 for Farrell's Java Programming with 2021 Updates, 9th Edition [Instant Access], 1 term
- Try to design a game in which the user has to guess a number and If it is in 100 to 125 then you have to show that his guess is right else print wrong guess in Java programming language.arrow_forwardPlease do this in Python Programming Scenario As you probably know, Sudoku is a number-placing puzzle played on a 9x9 board. The player has to fill the board in a very specific way: each row of the board must contain all digits from 0 to 9 (the order doesn't matter) each column of the board must contain all digits from 0 to 9 (again, the order doesn't matter) each of the nine 3x3 "tiles" (we will name them "sub-squares") of the table must contain all digits from 0 to 9. If you need more details, you can find them here. Your task is to write a program which: reads 9 rows of the Sudoku, each containing 9 digits (check carefully if the data entered are valid) outputs Yes if the Sudoku is valid, and No otherwise. Test your code using the data we've provided. Test data Sample input: 295743861 431865927 876192543 387459216 612387495 549216738 763524189 928671354 154938672 Sample output: Yes Sample input: 195743862 431865927 876192543 387459216 612387495 549216738 763524189 928671354…arrow_forwardJava program help Simulate a slot machine. The customer will add a fixed amount of money to the machine and play the slots. There should be 4 images for the game: "Apple", "Orange", "Banana", and "Cherry". If three of the images match, the customer wins $2 and is added to their balance. If all four match, the customer wins $10 and that is added to their balance. If less then four match there is no prize money, and the customer is charged $1 for the try. The customer can quit after each try, and the program will print out the customer's cash balance. Coding Details: Use an array of strings to store the 4 strings listed above. Use a do-while loop for the program. The program starts once the user enters how much money they have. The decision to stop occurs at the bottom of the loop. The do-while loop keeps going until the user quits, or there is no money left. The pseudocode for the program is shown below: Determine the fruits to display (step 3 below) and print them Determine if there…arrow_forward
- IN JAVA please not python In this game, one flyand three frogs are placed randomly on a board with the size 7x7.In each iteration, they move randomlywithin the board, and the simulation stops when one of the frogs eats the fly.Fly and frogs are essentially creatures that can move, make noise, and eat. Frogs can move up to 2squares in any direction, and flies can move up to 1. Frogs make the "Croak! Croak!" sound, and fliesmake "ZzzZZz!". Since frogs should not eat their kind, a function of "isEatable" should also beimplemented in decision making. A variable or function to check if the fly is alive is also required as aterminate condition for simulation.In each iteration, an 'f' character represents frogs' position on board, and an '*' character is used torepresent the position of fly. Java language pleasearrow_forwardA Memory Matching Game in java code with a 4x4 grid of Squares that when you click on a square it shows a number. It would have to be 2 of each number 1-8 and if the two squares that are clicked match then the squares stay on the grid. If they do not match after picking 2 squares they flip back overarrow_forward6 11 12 13 8 9 points = [10, 7, 4, 1] scores=0 15 16 17 18 19 20 21 22 23 29 38 31 32 33 34 35 36 37 38 39 40 41 This project is a fun game that generates a random number in a certain specified range and the user must guess the number after receiving hints. Every time a user's guess is wrong they are prompted with more hints to make it easier at the cost of reducing the score. from random import randint 44 45 24 25 26 27 def guessNumber(): 28 def generateNumber(): 51 52 53 54 55 56 57 return randint (10, 20) def generateHint (secretNumber, userGuess, rounds): if rounds == 0: hint = "The number is between 10 and 20" elif rounds == 1: hint= "The number is a even number" if secretNumber % 2 == 0 else "The number is an odd number" else: hint = "The number is lesser" if userGuess > secretNumber else "The number is greater" return hint secretNumber = generateNumber() for eachRound in range(0, 4): user Input = int(input("Enter your guess: ")) if userInput == secretNumber: print("Hurray! You…arrow_forward
- You are hired by a game design company and one of their most popular games is The Journey. The game has a ton of quests, and for a player to win, the player must finish all the quests. There are a total of N quests in the game. Here is how the game works: the player can arbitrarily pick one of the N quests to start from. Once the player completes a quest, they unlock some other quests. The player can then choose one of the unlocked quests and complete it, and so on. For instance, let’s say that this game had only 4 quests: A, B, C, and D. Let’s say that after you complete • quest A, you unlock quests [B, D]. • quest B, you unlock quests [C, D]. • quest C, you unlock nothing [ ]. • quest D, you unlock quest [C]. Is this game winnable? Yes, because of the following scenario: The player picks quest A to start with. At the end of the quest A, the unlocked list contains [B, D]. Say that player chooses to do quest B, then the…arrow_forwardYou are going to write a simulation for a mini survival game. In this game, one flyand three frogs are placed randomly on a board with the size 7x7.In each iteration, they move randomlywithin the board, and the simulation stops when one of the frogs eats the fly.Fly and frogs are essentially creatures that can move, make noise, and eat. Frogs can move up to 2squares in any direction and flies can move up to 1. Frogs make the "Croak! Croak!" sound, and fliesmake "ZzzZZz!". Since frogs should not eat their kind, a function of "isEatable" should also beimplemented in decision making. A variable or function to check if the fly is alive is also required as aterminate condition for simulation.In each iteration, an 'f' character represents frogs' position on board, and an '*' character is used torepresent the position of fly. Use the topics (Abstract classes, Interface, etc.) to implementthe simulation. (in java) An example output is given below.arrow_forwardJava - Encapsulation A rectangle can be formed given two points, the top left point and the bottom right point. Assuming that the top left corner of the console is point (0, 0), the bottom right corner of the console is point (MAX, MAX) and given two points (all “x” and “y” coordinates are positive), you should be able to draw the rectangle in the correct location, determine if it is a square or a rectangle, and compute for its area, perimeter and center point. To be able to do this, you should create a class Point (that has an x-coordinate and a y-coordinate). Also, create another class called Rectangle. The Rectangle should have 2 points, the top left and the bottom right. You should also implement the following methods for the Rectangle: display() - draws the rectangle on the console based on the samplearea() - computes and returns the area of a given rectangleperimeter() - computes and returns the perimeter of a given rectanglecenterPoint() - computes and returns the center point…arrow_forward
- A robot starts on a point marked “A” on a rectangular grid of points. The starting point is always the top left point on the grid. The robot can move left, right, up or down, moving from one point to the next. By moving in steps going left, right, up or down, the robot would like to reach a point marked “B”, which is always the bottom right point in the grid. Sometimes, points are marked as “x”, and the robot is not allowed to visit them at all. A robot is never allowed to visit a point more than once. In how many ways can the robot move from A to B and visit all points along the way? For example, in the following grid, represented in text as A . . . . B there is only one path from A to B: In the following grid, represented in text as A . . x x B there is still only one path (we're lucky because of the two x's): However, in the grid A . . . x B there are no ways for the robot to move from A to B and visit all points that are not marked with “x”. Write a single…arrow_forwardIn computer graphicsarrow_forwardChildren often play a memory game in which a deck of cards containing matching pairs is used. The cardsare shuffled and placed face down on a table. The players then take turns and select two cards at a time.If both cards match, they are left face up; otherwise, the cards are placed face down at the same positions.Once the players see the selected pair of cards and if the cards do not match, then they can memorize thecards and use their memory to select the next pair of cards. The game continues until all the cards areface up. Write a program to play the memory game. Use a two-dimensional array of 4 rows and 4 columnsfor a deck of 16 cards with 8 matching pairs. You can use numbers 1 to 8 to mark the cards. (If you use a6 by 6 array, then you will need 18 matching pairs, and so on.) Use random number generators torandomly store the pairs in the array. Use appropriate functions in your program, and the main programshould be merely a call to functions. I need to figure out how to do…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage