Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Dice are used in many games. One die can be thrown to randomly show a value from 1 through 6 . Design a Die class

Dice are used in many games. One die can be thrown to randomly show a value from 1 through 6. Design a Die class that can hold an integer data field for a value (from 1 to 6). Include a constructor that randomly assigns a value to a die object. For example, the following statement generates a random number between LOWEST_DIE_VALUE (which should contain the value 1) and HIGHEST_DIE_VALUE (which should contain the value 6) and assigns it to a variable.
randomValue =((int)(Math.random()*100)% HIGHEST_DIE_VALUE + LOWEST_DIE_VALUE);
Also include a method in the class to return a Die's value. Save the class as Die.java. Write an application that randomly "throws" two dice and displays their values. Save the application as TwoDice.java.
Using the Die class, write an application that randomly "throws" five dice for the computer and five dice for the player. Display the values and then, by observing the results, decide who wins based on the following hierarchy of Die values. (The computer will not decide the winner; the player will determine the winner based on observation. Later, you will learn to program the determination of the winner.) Any higher combination beats a lower one; for example, five of a kind beats four of a kind.
Five of a kind
Four of a kind
Three of a kind
A pair
After you learn about decision making, you will be able to make the program determine whether you or the computer had the better roll. For now, just observe how the values change as you execute the program multiple times. Save the application as FiveDice.java.
Create a zip file of the .java file(s) and submit the assignment.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago