EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Question
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.
- Define the method “main ()”,
Expert Solution & Answer
Trending nowThis is a popular solution!
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…
Chapter 5 Solutions
EBK JAVA PROGRAMMING
Ch. 5 - Prob. 1RQCh. 5 - Prob. 2RQCh. 5 - Prob. 3RQCh. 5 - Prob. 4RQCh. 5 - Prob. 5RQCh. 5 - Prob. 6RQCh. 5 - Prob. 7RQCh. 5 - Prob. 8RQCh. 5 - Prob. 9RQCh. 5 - Prob. 10RQ
Ch. 5 - Prob. 11RQCh. 5 - Prob. 12RQCh. 5 - Prob. 13RQCh. 5 - Prob. 14RQCh. 5 - Prob. 16RQCh. 5 - Prob. 17RQCh. 5 - Prob. 18RQCh. 5 - Prob. 19RQCh. 5 - Prob. 20RQCh. 5 - Prob. 1PECh. 5 - Prob. 2PECh. 5 - Prob. 3PECh. 5 - Prob. 4PECh. 5 - Prob. 5PECh. 5 - Prob. 6PECh. 5 - Prob. 7PECh. 5 - Prob. 8PECh. 5 - Prob. 9PECh. 5 - Prob. 10PECh. 5 - Prob. 1GZCh. 5 - Prob. 2GZCh. 5 - Prob. 3GZCh. 5 - Prob. 4GZCh. 5 - Prob. 5GZ
Knowledge Booster
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
- Create an application that allows you to play the Rock-Paper-Scissors game against the computer. When played between two people, each chooses one of three possibilities (typically indicated by a hand gesture) at the same moment, and the winner is chosen.Rock defeats Scissors, Scissors defeats Paper, and Paper defeats Rock in the game. The programme should choose one of the three alternatives at random (without exposing it) and then prompt the user to choose. The programme then displays both options and publishes a statement stating whether the user won, the machine won, or it was a tie. Continue to play till the user decides to stop. The number of user wins, losses, and ties is then printed.arrow_forwardWrite an application that allows the user to choose insurance options inJCheckBoxes. Use a ButtonGroup to allow the user to select only one of twoinsurance types—HMO (health maintenance organization) or PPO (preferredprovider organization). Use regular (single) JCheckBoxes for dental insurance andvision insurance options; the user can select one option, both options, or neitheroption. As the user selects each option, display its name and price in a text field;the HMO costs $200 per month, the PPO costs $600 per month, the dentalcoverage adds $75 per month, and the vision care adds $20 per month. When auser deselects an item, make the text field blank. Be sure to include & test any and all Exception Handling. Save the file as JInsurance.java.arrow_forwardCreate a lottery game application and name the program as LotteryGame.java. Generate three random numbers, each between 0 and 9. Allow the user to guess three numbers. Compare each of the user's guesses to the three random numbers and display a message that includes the user's guess, the randomly determined three digits, and the amount of money the user has won.arrow_forward
- Use a TextArea, and its setText() and append() methods to write an application that allows the user to select options for a dormitory room. Use CheckBoxes for options such as private room, Internet connection, cable TV connection, microwave, refrigerator, and so on. When the application starts, use a text area to display an appropriate message. After the user has selected the desired options, replace the message in the text area so it displays a running list of the user’s choices.arrow_forwardThe date June 10, 1960, is special because when it is written in the following format, the month times the day equals the year: 6/10/60 Create an application that lets the user enter a month (in numeric form), a day, and a two-digit year. The program should then determine whether the month times the day equals the year. If so, it should display a message saying the date is magic. Otherwise, it should display a message saying the date is not magic.arrow_forwardIn Chapter 2, you created an interactive application named GreenvilleRevenue, and in Chapter 3 you created a GUI version of the application named GreenvilleRevenueGUI. The programs prompt a user for the number of contestants entered in this years and last years Greenville Idol competition, and then they display the revenue expected for this years competition if each contestant pays a $25 entrance fee. The programs also display a statement that compares the number of contestants each year. Now, replace that statement with one of the following messages: If the competition has more than twice as many contestants as last year, display The competition is more than twice as big this year! If the competition is bigger than last years but not more than twice as big, display The competition is bigger than ever! If the competition is smaller than last years, display, A tighter race this year! Come out and cast your vote!arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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