Question
Need help correcting code import java.util.Scanner; public class Games { public static void main(String args[]) { miniMadLibs(); GuessTheNumber(); } public static void miniMadLibs() { String
Need help correcting code
import java.util.Scanner;
public class Games { public static void main(String args[]) { miniMadLibs(); GuessTheNumber(); }
public static void miniMadLibs() { String word1,word2,word3,word4,word5; System.out.println("Welcome to madLibs, A word replacement Game "); System.out.println(" ---------------------------------------"); System.out.println("Please input the words to replace the words given in DUBLE QUOTES" + " in below sentences"); Scanner scan = new Scanner(System.in); System.out.print(" But his \"soul\" was mad "); word1=scan.nextLine(); System.out.print("Being alone in the \"wilderness\" "); word2=scan.nextLine(); System.out.print("it had looked within \"itself\" and, "); word3=scan.nextLine(); System.out.print("by \"heavens\" I tell you "); word4=scan.nextLine(); System.out.print("\"it\" had gone mad "); word5=scan.nextLine(); System.out.println(" New sentences with replaced words are "); System.out.println("But his "+word1+" was mad"); System.out.println("Being alone in the "+word2); System.out.println("it had looked within "+word3+" and,"); System.out.println("by "+word4+" I tell you"); System.out.println(word5+" had gone mad"); }
public static void GuessTheNumber() { System.out.println(" ---------------------------------------"); System.out.println(" Welcome to number guessing game"); int min, max,guess,difference; Scanner scan = new Scanner(System.in); System.out.print("Enter minimum range of number to generate random numbers: "); min=scan.nextInt(); System.out.print("Enter maximum range of number: "); max=scan.nextInt(); System.out.print("Enter your guess: "); guess=scan.nextInt(); Random rand = new Random(340L); int randNum = rand.nextInt((max-min)+1)+min; System.out.println("Range: "+min+"-"+max); if(guess>randNum) { difference = guess-randNum; System.out.println("The difference between the generated number and" + "your guess is: "+guess+"-"+randNum+" = "+difference); } else { difference=randNum-guess; System.out.println("The difference between the generated number and" + " your guess is: "+randNum+"-"+guess+" = "+difference);
2.T Lab2d Due Sep-2T Introduction This lab holds the purpose of extra practice declaring and assigning different types of variables. To do this, you will program two simple games, one that focuses on using strings and one that focuses on using numerical data. We will call the class Games .java We will focus on these common types, but be aware there are many more that will be introduced as the semester continues. Mini MadLib MadLibs is a fun word replacement game used to teach children about parts of speech. We will use this format to get information from the user and replace the words in double parens in the following piece of text: But his (sou) was mad. Being alone in the ((wilderness), it had looked within (itself) and, by (heavens) I tell you, (it) had gone mad. That is, your program should accept 5 nouns. Guess the Number Now we will create a number guessing game in which the user specifies a range of numbers. The program will then generate a number within that range and the users guesses what it is. The program will then output the difference between the generated number and the guess You will need to use Java's Random class and the seed: 340L so that the numbers will become predictable for testing purposes. The declaration and initializatoin of the Random variable will look something like this: Random rand = new Random (340L) ; The Random class has a method called nextInt(O For parameters (values given in the parenthises), it can take a maximum value that is exclusive. So if you passed (put in parentheses) the number 5, the generator would give a number 0-4. Using the user provided max and min, manipulate the Random number generator so that it gives numbers in the range [min,max] (That is the range is inclusive. Hint: Google is your friend
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started