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

Videos

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

Dice game

Program plan:

  • In a file “Die.java”, create a class “Die”,
    • Declare and initialize the necessary variables.
    • Define the constructor “Die()”to compute the value in terms of random number.
    • Define the method “get_Value()” to return the value.
  • In a file “TwoDice2.java”, create a class “TwoDice2”,
    • Define the method “main ()”,
      • Create two objects for “Die” class.
      • Assign the first die value returned from the “get_Value()” method.
      • Assign the second die value returned from the “get_Value()” method.
      • Print two die values.
      • Check whether the first die value is greater than the second die value,
        • If it is true, print the message as “First die value is greater”.
      • Otherwise, check whether the second die value is greater than the first die value,
        • If it is true, print “Second die value is greater”.
      • Otherwise, print “The dice are equal”.

Blurred answer
Students have asked these similar questions
Write 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.
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.
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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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