Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m in java one and need help with this code. please follow the directions give

ID: 3684114 • Letter: I

Question

I'm in java one and need help with this code. please follow the directions given and test your program to make sure it works as it is required. I will apreciate your help. thank you.please use the given code. make sure that your program doesn't gives an infinity loop.

Programming Concepts

1. Random Number Generation

Exercise Location

For this exercise, you will copy a program from my directory into yours. It doesn't matter what directory this exercise is located in. You will need to copy this command and paste it into Loki:please use the given code

cp ~lkoperski/1404_Lab/Exercises/Exercise10.java .

Exercise Description

^ You will create a game that has the user guess a number between 1 and 10.

^ Generate a random number that the user will attempt to guess.

^ If the user guesses a number that is lower than the answer, print a message that says that.

^ If the user guesses a number that is higher than the answer, print a message that says that.

^ If the user guesses a number that is equal to the answer, print a message that says that.

user@loki:~$ java Exercise10

I am thinking of a number between 1 and 10!

Enter a guess: 5   

Too low!

Enter a guess: 8   

Too high!

Enter a guess: 6

Too low!

Enter a guess:   7

You guessed it!

Explanation / Answer

Please run this program and enter value and see message according to your requirement.

Change class name according to your file.

/*

Import scanner and random package

*/

import java.util.Scanner;

import java.util.Random;

// define class HelloWorld

// Please change class name according to your Exercise10 class

public class HelloWorld{

                // define main function here

public static void main(String []args){

                // create scanner object here

                                Scanner in = new Scanner(System.in);

                                // create random number object here

                                Random r= new Random();

                                // create random number between 1 to 10

                                int answer = r.nextInt(10) + 1;

                                int guess=0;

                                // show message for player

                                System.out.println("I am thinking of a number between 1 and 10!");

                                // show message for player. Enter number

                                System.out.println("Enter a guess:");

                                guess = in.nextInt();

                                System.out.println(answer);

                                // check enter number with random number and show message.

                                if(answer > guess){

                                                System.out.println("Too low!");

                                }else if(answer < guess){

                                                System.out.println("Too high!");

                                }else{

                                                System.out.println("You guessed it!");

                                }

                }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote