Concept explainers
Random Numbers:
Most computer programs do the same thing every time they run; programs like that are called deterministic. Usually, determinism is a good thing, since we expect the same calculation to yield the same result. But for some applications, we want the computer to be unpredictable. Games are an obvious example, but there are many others, like scientific simulations.
We have already seen java.util.Random, which generates pseudorandom numbers. The method nextInt takes an integer argument, n, and returns a random integer between 0 and n - 1.
Assignment:
For this assignment you will write a program in java to simulate a guessing game. Your program will generate a random number in a certain range (let the user define the range) and ask the user to guess what number it is. Give the user a certain number of tries while you narrow down the possibilities. For example, let's say the number generated is 67 and the user has 5 tries, this could be your program's output:
This is a guessing game.
Please enter the lower and highest values for the range: 1 100
I'm thinking of number between 1 and 100. Guess what it is:
50
Too low! Try again:
75
Too high! Try again:
65
To low! Try again:
70
To high! Try again:
68
You lost! The number was 67.
Step by stepSolved in 2 steps with 3 images
- In Python, Solve the locker riddle which reads as follows:Imagine 100 lockers numbered 1 to 100 with 100 students lined up in front of those 100lockers:The first student opens every locker.The second student closes every 2nd locker.The 3rd student changes every 3rd locker; if it’s closed, she opens it; if it’s open, she closes it.The 4th student changes every fourth locker (e.g., 4th, 8th, etc.).The 5th student changes every 5th locker (e.g., 5th, 10th, etc.).That same pattern continues for all 100 students. Which lockers are left open after all 100 students have walked the rowof lockers?arrow_forwardA program in javaarrow_forwardjava Write an interface for Animal. We will say that every Animal will make a sound and will also be able to give its type.arrow_forward
- Is there a way to create a java program on Branching and selecting method on problems like this? Suppose that we are working for an online service that provides a bulletin board for its users. We would like to give our users the option of filtering out profanity. Suppose that we consider the words cat dog and rabbit to be profane. Write a program that reads a string from the keyboard and test whether the string contain any one of these words. Your program should find words like cAt that differ only in case. Have your program reject only lines that contain one or more of the three words exactly. For example, concatenation is a small category should not be considered profane. This problem can be solved easily. If you add a space to the beginning of the string and a space at the end of the string you only need to check if space cat space or space dog space or space rabbit space is in the string. Use three if statements; one for each word. If one or more of the words are there set…arrow_forwardTHIS IS MEANT TO BE WRITTEN IN JAVA. The assignment is to get an integer from input, and output that integer squared, ending with newline. Where i'm doing my assignment, in a seperate part of the assignment outside of the code, there's an option that says, "Enter program input ". What do I write? This is what I have so far and it doesn't run... import java.util.Scanner; public class NumSquared {public static void main(String[] args) {//main() methodScanner scnr = new Scanner(System.in);//declaring variable to store user inputint userNum;//declaring variable to store square of a numberint userNumSquared;//reading numberuserNum = scnr.nextInt();//multiplying number to it self to find squareuserNumSquared = userNum *userNum;//print square of a numberSystem.out.print(userNumSquared);} Please explain why it's not running and please show the completed code.arrow_forwardPlease help me solve this with java .... just the HangMan HangMan instruction class : • HangMan is a game in which a player tries to guess a word based on a given hint. For example, if the given hint is “movie”, then the player must guess a movie name. If the given hint is a “country”, then the player must guess a country name, and so on.• The game starts by showing a message on the screen that shows the hint and all letters in the word but obscured as dashes (-). Then, the game will allow the player to guess 5 letters. If the player gives a letter that actually exists in the word, then this letter will be revealed. Afterwards, the game will ask the player to give the answer. If the given answer is correct, then the game will show a message that the player has won 5 points. Otherwise, the game will show a message that the player has lost. Below is one possible game scenario, in which the word is “iron man”, and the hint is “movie”. Note that the text in green color is the…arrow_forward
- There are three main operations on rectangles: intersection, union, and difference. Among them, only intersection is guaranteed to return another rectangle. In general, the union of two rectangles is... two rectangles, and the difference between two rectangles is ... a whole lot of rectangles, as we will see. We let you implement rectangle intersection. Of course, the intersection is defined only if the rectangles have the same number of dimensions. The intersection is computed by taking the intersection of the intervals of the two rectangles for corresponding dimensions. If one of the intervals is empty, you should return None. [] # @ title Rectangle intersection def rectangle_and(self, other): if self.ndims != other.ndims: raise TypeError("The rectangles have different dimensions: {} and {}".format( )) self.ndims, other.ndims ### YOUR SOLUTION HERE Rectangle. _and_ = rectangle_and [ ] r1 = Rectangle((2, 3), (0, 4)) r2 = Rectangle((0, 4), (1, 3)) draw rectangles (r1, r2) draw…arrow_forwardWrite a Java program that implements the class scrabble by following the design given below: . Scrabble A word String Scrabble(String) m- getScore() Powered by yFiles int Given a word, compute the scrabble score for that word with method getscore(). Letter Values You'll need these: Letter Value A, E, I, 0, U, L, N, R, S, T 1 D, G 2 В, С, М, Р 3 F, H, V, W, Y K 5 J, X 8. Q, z 10arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education