Question: Write a method named lucky that accepts a Random generator object named rand and an integer parameter lowCutOff. The method rolls a 6-sided die until
Write a method named lucky that accepts a Random generator object named rand and an integer parameter lowCutOff. The method "rolls" a 6-sided die until it gets four consecutive rolls in a row that have values lowCutOff or higher. As the method rolls the die it should print each value rolled. At the end, it should print a message indicating how many rolls were made.
For example, the call of lucky (rand, 3) might print output such as the following below. Notice that the method stops after rolling 5, 5, 3, and 4 consecutively because these are all values of 3 or higher. In the example, lucky(rand, 2) notice that the method stops after rolling 3, 6, 3, 5 consecutively because these are all values of 2 or higher.
Note: You may assume that the parameter value passed to lowCutOff will be between 1 and 6 inclusive. You should also assume you need to randomize a standard die whose values are between 1-6 inclusive.
Programming Language: Java
Sample Output:
Call | lucky(rand, 3) | lucky(rand, 2)
Sample Run: | 5246125534 (Finished after 10 rolls) | 13635 (Finished after 5 rolls)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
