Java Programming, Loose-Leaf Version
Java Programming, Loose-Leaf Version
9th Edition
ISBN: 9781337685900
Author: FARRELL, Joyce
Publisher: Cengage Learning
bartleby

Videos

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

Generate random numbers and find out which one is greater

Program plan:

Filename: “Die.java”

  • Define the “Die” class
    • Declare the required variables.
    • Define the constructor
      • Set the values
    • Define the “generateRandom” method
      • Determine the random value and return it
    • Define the “getValue” method
      • Return the value.

Filename: “TwoDice.java”

  • Define the “TwoDice” class
    • Define the main method.
      • Create the objects for “Die” class
      • Declare the variables and call the “getValue” method with the different “Die” objects.
      • Display the first and second dice values
      • Check “x” is greater than “y” or not.
        • If the condition is true, then display “x” is greater.
      • Check “x” is less than “y” or not.
        • If the condition is true, then display “x” is lesser.
      • Otherwise, display both the values are equal.

Blurred answer
Students have asked these similar questions
Screen shot please
JAVA   Write an application to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12, with 7 being the most frequent sum, and 2 and 12 the least frequent.
In this exercise, you have to implement a calculator which can perform addition, subtraction, multiplication, and division. Problem Statement# Write a Java class called Calculator with ● private fields: ○ num1 and num2 (double type) And methods: ● add(), a method which returns the addition of two numbers ● subtract(), a method which returns the subtraction of num1 from num2 ● multiply(), a method which returns the multiplication of numbers ● divide(), a method which returns the division of num2 by num1 ● Define a parameterized constructor which takes two parameters num1 and num2 and assigns these variables to the respective fields in the class. Input# Pass double point numbers in the parameterized constructor Output# addition, subtraction, division, and multiplication Sample Input# Calculator obj = new Calculator(10, 94); obj.add() obj.subtract() obj.multiply() obj.divide() Sample Output# 104 84 940 9.4 Part of the Solution class Calculator { // write class fields here public…
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
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
Memory Management Tutorial in Java | Java Stack vs Heap | Java Training | Edureka; Author: edureka!;https://www.youtube.com/watch?v=fM8yj93X80s;License: Standard YouTube License, CC-BY