Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(a) Create a Java class named RiskyDice (b) For this lab, I am providing you with the main method, as shown here: public static

image text in transcribedimage text in transcribed

(a) Create a Java class named RiskyDice (b) For this lab, I am providing you with the main method, as shown here: public static void main(String[] args) { int pg = determine Play() ; if (pg != -1) { playGame (pg); } } (c) Above the main method, create a Random object. Make it a public static object, so that we can use it in any of our methods. (d) For this lab, we are making a dice game. You must first prompt the user for whether or not they wish to play the game. If the user does not want to play, exit. Otherwise, your program must simulate rolling a pair of dice between 3 to 5 times, as specified by the user. If the user specifies a number of rolls below 3, or above 5, you must re-prompt the user until they provide an appropriate number of rolls. After the rolls are complete, a single match means the user wins, otherwise the computer wins. (e) Your program needs the following methods that perform the following actions: determinePlay o determinePlay should return an integer and take no arguments o determinePlay should first ask if the user wants to play the game. You can use console input with a Scanner, or a JOptionPane InputDialog. If the user wants to play, determinePlay should prompt the user for the number of times they want to roll dice, between 3 and 5. If invalid input is O provided, prompt the user of their error and try again until receiving valid input. o After getting the number of times the dice will be rolled, the method should return that number. o If the user doesn't want to play, return -1 to quit, as shown in the provided main method playGame a. playGame should have no return type b. playGame should take the number of times the dice will be rolled as an argument c. playGame should use a method called rollDice to roll two dice d. rollDice should be called and checked, as many times as the user specified, using a for loop e. In the dice ever match, the game should end with the player's victory f. If none of the rolls match, the game should end with the player's loss g. This method MUST use System.exit(0) to end the program when the user has won or lost rollDice a. rollDice takes no argument b. rollDice should roll two dice using the Random object (that is, generate two numbers between 1 and 6, both inclusive) c. If the dice match, the player wins and the playGame method should terminate the program. Note that this function is invoked in the playGame function. d. It is up to you to choose what return type rollDice has it should be clear whether or not the dice matched through whatever return value you use. (f) Feel free to add more methods, if you feel a need for it. For example, you could have a method to get the random dice roll value.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Heres the implementation of the RiskyDice class based on the provided requirements java import javau... 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

Java How To Program Late Objects Version

Authors: Paul Deitel, Deitel & Associates

8th Edition

0136123716, 9780136123712

More Books

Students also viewed these Programming questions