In: Computer Science
Using ECLIPSE IDE
Write a Java Program to play your version of the Texas Pick 3 Lottery. You will need to include the provided code given below in your program.
Task:The program will prompt for a number between 0 and 999. Your program will display the number of attempts it took for the entered number to match a randomly generated number.
Enter your Pick 3 choice 0-999: 554
PlayCounter = 1343 ( This result will vary )
Include the code below in your program. The code also requires the following import line:
import java.util.concurrent.ThreadLocalRandom;
/**
* officialPlayPick3()
* Returns a random number from 0 to 999
* @return int
*/
public static int officialPlayPick3() {
final int MIN_RANGE_VALUE = 0;
final int MAX_RANGE_VALUE = 999;
return
ThreadLocalRandom.current().nextInt(MIN_RANGE_VALUE,MAX_RANGE_VALUE
+ 1);
}
SOLUTION-
I have solve the problem in Java code with screenshot for easy
understanding :)
CODE-
import java.util.Scanner;
import java.util.concurrent.ThreadLocalRandom;
public class LotteryGame {
static void playPick3(int myPick3)
{
int playCounter=0;
int myPick3Result;
while(true)
{
myPick3Result=officialPlayPick3();
if(myPick3Result==myPick3)
{
System.out.println("PlayCounter =
"+playCounter);
return;
}
else
{
playCounter++;
}
}
}
static int officialPlayPick3()
{
final int MIN_RANGE_VALUE = 0;
final int MAX_RANGE_VALUE = 999;
return
ThreadLocalRandom.current().nextInt(MIN_RANGE_VALUE,MAX_RANGE_VALUE
+ 1);
}
public static void main(String[] args) {
// TODO Auto-generated method
stub
int myPick3choice;
Scanner sc=new
Scanner(System.in);
System.out.print("Enter your Pick 3
choice:0-999: ");
myPick3choice=sc.nextInt();
playPick3(myPick3choice);
}
}
SCREENSHOT-
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL
SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------