EBK JAVA PROGRAMMING
8th Edition
ISBN: 9781305480537
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Question
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.
- Define the main method.
Expert Solution & Answer
Trending nowThis is a popular solution!
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…
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…
Look at the header of the method below, and then implement a sample call to it in your code.private static void ShowValue ()
Chapter 4 Solutions
EBK JAVA PROGRAMMING
Ch. 4 - Prob. 1RQCh. 4 - Prob. 2RQCh. 4 - Prob. 3RQCh. 4 - Prob. 4RQCh. 4 - Prob. 5RQCh. 4 - Prob. 6RQCh. 4 - Prob. 7RQCh. 4 - Prob. 8RQCh. 4 - Prob. 9RQCh. 4 - Prob. 10RQ
Ch. 4 - Prob. 11RQCh. 4 - Prob. 12RQCh. 4 - Prob. 13RQCh. 4 - Prob. 14RQCh. 4 - Prob. 15RQCh. 4 - Prob. 16RQCh. 4 - Prob. 17RQCh. 4 - Prob. 18RQCh. 4 - Prob. 19RQCh. 4 - Prob. 20RQCh. 4 - Prob. 1PECh. 4 - Prob. 2PECh. 4 - Prob. 3PECh. 4 - Prob. 4PECh. 4 - Prob. 5PECh. 4 - Prob. 6PECh. 4 - Prob. 7PECh. 4 - Prob. 8PECh. 4 - Prob. 9PECh. 4 - Prob. 10PECh. 4 - Prob. 11PECh. 4 - Prob. 12PECh. 4 - Prob. 1GZCh. 4 - Prob. 2GZ
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
- 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.arrow_forwardInstructor note: This lab is part of the assignment for this chapter. HINT: 1). The decision means how many times to flip the coin. 2). Use a random integer variable to indicate the head or tail in each toss. Java Define a method named coinFlip that takes a Random object and returns "Heads" or "Tails" according to a random value 1 or 0. Assume the value 1 represents "Heads" and 0 represents "Tails". Then, write a main program that reads the desired number of coin flips as an input, calls method coinFlip() repeatedly according to the number of coin flips, and outputs the results. Assume the input is a value greater than 0. Ex: If the random object is created with a seed value of 2 and the input is: 3 the output is: Heads Tails Heads Note: For testing purposes, a Random object is created in the main() method using a pseudo-random number generator with a fixed seed value. The program uses a seed value of 2 during development, but when submitted, a different seed value may be used…arrow_forwardCreate a program that will count the number of numeric characters in an input string. The program should be able to ask the user for the input string and should be able to display the number of numeric characters on the screen. For this exercise, you should create your class to handle the different operations. Remember that any input/output operations should be done in the main method while all calculations should be done inside the class. Remember that you need to apply encapsulation in your class. Sample Output: Enter a string: Hello 123 Number of numeric characters: 3arrow_forward
- Class RightTriangle Represents a right triangle by the length of each of its two legs Includes the default and overloaded constructor, methods to set the length of each of the two legs, amethod to get the area, a method to scale the size of the triangle, a method to invert the triangle(swap the lengths of its two legs), and a method to print its dimensions.Class TestRightTriangle Creates and initializes two triangles. Calls the various associated methods to set its size, compute its area, scale its size, invert, and print itsdimensions.You are required to implement both classes according to the requirements specified in the commentsdisplayed in the .java files. The following is an example of possible output:triangle1 dimensions: 6.0 3.5triangle1 area: 10.5triangle2 dimensions: 3.0 4.0triangle2 area: 6.0triangle1 dimensions: 18.0 10.5triangle2 dimensions: 5.5 6.5triangle1 dimensions: 4.5 2.625triangle1 dimensions after invert: 2.625 4.5A few details: Do NOT modify any of the code…arrow_forwardCode the following: Language : Java Create a method called triangle that will take in three angles and tell you if you have a triangle Create an overloaded version of the triangle method that only takes in one angle and tells you if it could be a triangle create an overloaded version of the triangle method that only takes in two angles. You must check if it's possible for it to be an isosceles triangle. Don't forget to check both angles : example: angle1*2 + angle2 == 180 or angle1 +angle2*2 == 180arrow_forwardJava programarrow_forward
- java Alejandro has many emails, but only has time to read a few of them. Help him sort his inbox by checking the given email variable for his name and for the word 'project'. Use the following requirements to help Alejandro: If the email has his name and the word 'project' print: priority If the email has only his name, but not the word 'project' print: read If the email does not have his name print: don't readarrow_forwardLook through the method header below, then, as an example, write a call to the method. an internal void ShowValue()arrow_forwardLook through the method header below, then, as an example, write a call to the method.an internal void ShowValue()arrow_forward
- true of false: a) The first step in any programming task is to start coding. b) The only places we would ever want to put a comment in our code are above a method and above a class.arrow_forwardUSE JAVA IDE Create a class that has three methods. One method is to input three numbers. The second method will return the largest number between the three numbers. The third method will return the smallest number between the three numbers. Since the largest and smallest number are both returned values, display these values in the main method.arrow_forwardJavaStudents will be creating a simple trivia game for two players. The program will work like the following: Starting with player 1, each player gets a turn answering 5 trivia questions (There are 10 questions, 5 for each player). When a question is displayed, four possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, he or she earns a point.After answers have been selected for all of the questions, the program displays the number of points earned by each player and declares the player with the highest number of points the winner.You are to design a Question class to hold the data for a trivia question. The Question class should have String fields for the following data: A trivia questionPossible answer 1Possible answer 2Possible answer 3Possible answer 4The number of the correct answer (1,2,3, or 4)The Question class should have appropriate constructor(s), accessor, and mutator methods. The program should create an…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
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