Java Programming (MindTap Course List)
Java Programming (MindTap Course List)
9th Edition
ISBN: 9781337397070
Author: Joyce Farrell
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
Problem: Bugs are simple creatures that only know how to walk towards other bugs. Bugs maintain information about their (x, y) position; by which it can tell if they are standing next to other bugs. Watch the following video: bug movement. Create a java project that simulate bugs movement. You need to write a class “Bug" that models a bug moving along a straight line and it can turn to change its direction counterclockwise (i.e. 90 degree to the left; north → west → south → east → north). In each move, its position changes by one unit in the current direction. Details of the "Bug" class is described below. Your simulator should read information of an unknown number of “Bug" objects from an input file called “Bugs.txt". Each line represents a bug and the initial position and facing direction of this particular bug. Keeping the first bug position as a reference the simulator should move the second bug next to the first bug forming a cluster and its final position and direction should be…
Java  Overview In this task, you should try using the Scanner class to read data from the keyboard. This data should be stored in variables in your program and then printed on screen.   Task You should write a class called Story that should include a main method. This programs should create a fairy tale for a child. The program is based on a completed story, but some words must be replaced with such as the user may enter. The fairy tale you are going to based on are the following:   The little ant (1) There was once a small, small ant that lived with its (2) and its (3) siblings in an anthill, by a large (4) in the forest. The little ant is called (1). For the most part, (1) and his siblings used to work on carrying (5) and (6) to the stack, but today it was (7), so (1) was free. The words that are crossed out are the words that your program should ask the user for. In total, there are seven entries the user must make. The program must save these entries in separate variables and then…
Python In this assignment, a game called treasure hunt will be written object oriented.There are 3 types of treasures in the game. Diamond, Emerald and Gold. Diamond is 100 points, Emerald 70 points and Gold is 50 points.There are thieves in the game that will prevent you from hunting for treasure. Encountering a thief they steal some of your treasure. You will randomly generate which thief will steal from which treasure and how much.At the beginning of the game, the player has no treasure. X, Y, Z and H will be randomly identified at the start of the game. Define X Diamonds, a random number between X -> 100-200.Let a random number be defined between Y Emerald Y -> 100-200.Define a random number between Z Gold Z -> 100-200.You will define H thieves. Let it be defined between H -> 5-20. It will collect these randomly selected treasures to the player.For example:1- Diamond2-Emerald3-Diamond4-Gold5-Thief (k = treasure to steal, n = how many pieces he can steal)6-Gold.... In…
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
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,
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