Write a complete standalone program in a single class called

Write a complete, stand-alone program in a single class called RandomSurprise, which works as follows:

Your program should prompt the user to enter a positive integer 1 to 9, then read in the non-negative int value from the keyboard and assign it to a variable named numFromUser.

The code then generates a random number in the range [1,9] (one to nine inclusive).

The code compares the random number to the input number. If they are equal, the code prints \"Got one!\", otherwise it prints \"Nothing\".

For example, if the number input was 3, and the random number generated was 7, the code would output:
Nothing

If the number input was 3, and the random number generated was 3, the code would output:
Got one!

Enter your complete program code for the RandomSurprise class below.

Write a complete, stand-alone program in a single class called RandomSurprise, which works as follows: Your program should prompt the user to enter a positive integer 1 to 9, then read in the non-negative int value from the keyboard and assign it to a variable named numFromUser. The code then generates a random number in the range [1, 9] (one to nine inclusive). The code compares the random number to the input number. If they are equal, the code prints \"Got one!\", otherwise it prints \"Nothing\". For example, if the number input was 3, and the random number generated was 7, the code would output: Nothing If the number input was 3, and the random number generated was 3, the code would output: Got one! Enter your complete program code for the RandomSurprise class below.

Solution

program

   class RandomSurprise
{
System.out.println(\"Please enter a positive integer seed value: \");
boolean flag = true;
while(flag) {
try {
seedValue = Integer.valueOf(input.nextLine());
if (seedValue <= 0) {
System.out.println(\"input is not a positive Integer \");
System.out.println(\"Please enter a positive integer seed value: \");
} else {
flag=false;
}
} catch(NumberFormatException e) {
System.out.println(\"input is not a positive Integer \");
System.out.println(\"Please enter a positive integer seed value: \");
}
}

Write a complete, stand-alone program in a single class called RandomSurprise, which works as follows: Your program should prompt the user to enter a positive i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site