Question

In: Computer Science

Using ECLIPSE IDE Write a Java Program to play your version of the Texas Pick 3...

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.

  1. In the main() method, declare an int named myPick3choice.
  2. Create a prompt for myPick3choice as "Enter your Pick 3 choice:0-999".
  3. Create a void method named playPick3 that has an int parameter named myPick3.
  4. In the playPick3 method, do the following:
    1. Create an int variable called playCounter and initialize it to 0.
    2. Create an int variable called myPick3Result.
    3. Create a loop that calls the method officialPlayPick3 (Provided below) and store the result in myPick3Result.
      1. If myPick3Result matches the variable myPick3, then display the result of playcounter as "PlayCounter = ...." and exit the loop.
      2. If myPick3Result does not match, increment the variable playCounter and continue the loop.

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);
}

Solutions

Expert Solution

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!!!!!!!!----------


Related Solutions

Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs...
write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the...
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the file PizzaOrder.java. Prompt the user to input the type of pizza that they want to order. In the end, you should print out the final order and price. Here is a sample output. Welcome to May and Adam’s Pizzeria Enter your first name: Amy Pizza Size(inches)     Cost         10            $10.99         12            $12.99         14            $14.99         16            $16.99 What size pizza would you...
I need to write a java program (in eclipse) that will read my text file and...
I need to write a java program (in eclipse) that will read my text file and replace specific placeholders with information provided in a second text file. For this assignment I am given a text file and I must replace <N>, <A>, <G>, with the information in the second file. For example the information can be John 22 male, and the template will then be modified and saved into a new file or files (because there will be multiple entries...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name, that does the following: Create two arrays that will hold related information. You can choose any information to store, but here are some examples: an array that holds a person's name and an array that hold's their phone number an array that holds a pet's name and an array that holds what type of animal that pet is an array that holds a student's...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name, that does the following: Declare an array reference variable called myFavoriteSnacks for an array of String type. Create the array so that it is able to hold 10 elements - no more, no less. Fill the array by having each array element contain a string stating one of your favorite foods/snacks. Note: Only write the name of the snack, NO numbers (i.e. Do not...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT