EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Videos

Question
Book Icon
Chapter 5, Problem 2GZ
Program Plan Intro

Lottery game application

Program plan:

  • Import necessary package.
  • Create a class “Lottery”,
    • Define the method “main ()”,
      • Declare and initialize the necessary variables.
      • Generate the three random numbers.
      • Combine three random numbers into a single three digit number.
      • Get the first digit entered into the first dialog box.
      • Assign the integer value returned form the method “parseInt()”.
      • Get the second digit entered into the second dialog box.
      • Assign the integer value returned form the method “parseInt()”.
      • Get the third digit entered into the third dialog box.
      • Assign the integer value returned form the method “parseInt()”.
      • Check whether the first, second and third digit is equal to the first, second and third random number generated respectively,
        • If it is true, set the match count to “4”.
      • Otherwise, check whether the first digit is equal to the first random number generated,
        • If it is true, increment the match count by “1”.
        • Set the first random value to “99”.
      • Otherwise, check whether the first digit is equal to the second random number generated,
        • If it is true, increment the match count by “1”.
        • Set the first random value to “99”.
      • Otherwise, check whether the first digit is equal to the third random number generated,
        • If it is true, increment the match count by “1”.
        • Set the first random value to “99”.
      • Check whether the second digit is equal to the first random number generated,
        • If it is true, increment the match count by “1”.
        • Set the first random value to “99”.
      • Otherwise, check whether the second digit is equal to the second random number generated,
        • If it is true, increment the match count by “1”.
        • Set the first random value to “99”.
      • Otherwise, check whether the second digit is equal to the third random number generated,
        • If it is true, increment the match count by “1”.
        • Set the first random value to “99”.
      • Check whether the third digit is equal to the first random number generated,
        • If it is true, increment the match count by “1”.
        • Set the first random value to “99”.
      • Otherwise, check whether the third digit is equal to the second random number generated,
        • If it is true, increment the match count by “1”.
        • Set the first random value to “99”.
      • Otherwise, check whether the third digit is equal to the third random number generated,
        • If it is true, increment the match count by “1”.
        • Set the first random value to “99”.
      • Check whether the match count is “4”,
        • If it is true,set the highest winning.
      • Otherwise, check whether the match count is “3”,
        • Set the second best winning.
      • Otherwise, check whether the match count is “2”,
        • If it is true, set the third best winning.
      • Otherwise, check whether the match count is “1”,
        • If it is true, set the low winning.
      • Otherwise, set the winning to “0”.
      • Display the output message in dialog box.

Blurred answer
Students have asked these similar questions
Write an application that plays “guess the number” as follows:  Your application chooses the number to be guessed by selecting an integer at random in the range 1–10. The application then displays the following in a label:I have a number between 1 and 10. Can you guess my number?Please enter your first guess. A JTextField should be used to input the guess. As each guess is input  A JLabel should display either "Too High" or "Too Low" to help the user zero in on the correct answer.  When the user gets the correct answer, "Correct!" should be displayed, and the JTextField used for input should be changed to be uneditable. A JButton should be provided to allow the user to play the game again. When the JButton is clicked, a new random number should be generated and the input JTextField changed to be editable. Sample Output:
Write an application that plays “guess the number” as follows:  Your application chooses the number to be guessed by selecting an integer at random in the range 1–10. The application then displays the following in a label:I have a number between 1 and 10. Can you guess my number?Please enter your first guess. A JTextField should be used to input the guess. As each guess is input  A JLabel should display either "Too High" or "Too Low" to help the user zero in on the correct answer.  When the user gets the correct answer, "Correct!" should be displayed, and the JTextField used for input should be changed to be uneditable. A JButton should be provided to allow the user to play the game again. When the JButton is clicked, a new random number should be generated and the input JTextField changed to be editable.
Create an application that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows:1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Do not display the computer’s choice yet.)2. The user selects his or her choice of rock, paper, or scissors. To get this input you can use Button controls, or clickable PictureBox controls displaying some of the artwork that you will find in the student sample files.3. The computer’s choice is displayed.4. A winner is selected according to the following rules:• If one player chooses rock and the other player chooses scissors, then rock wins. (Rock smashes scissors.)• If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.)• If one player chooses…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
CPP Function Parameters | Returning Values from Functions | C++ Video Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=WqukJuBnLQU;License: Standard YouTube License, CC-BY