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: 3682883 • 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.

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:

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

/**** NumberGuessingGame.java ****/

import java.util.Scanner;

public class NumberGuessingGame {

public static void main(String[] args) {

int secretNumber;

secretNumber = (int) (Math.random() * 10 + 1);   

Scanner keyboard = new Scanner(System.in);

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

int guess;

do {

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

guess = keyboard.nextInt();

if (guess == secretNumber)

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

else if (guess < secretNumber)

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

else if (guess > secretNumber)

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

} while (guess != secretNumber);

}

}

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