Examlex

Solved

Programming Write a Method Named Lucky That Accepts an Integer Parameter

question 3

Essay

Programming
Write a method named lucky that accepts an integer parameter min and rolls a 6-sided die until it gets four consecutive rolls in a row that have values of min or less. As the method rolls the die it should print each value rolled, and then it should print a message at the end to indicate how many rolls were made. For example, the call of lucky(3); should print output such as the following (though the output would be different on every call because of randomness). Notice that the method stops after rolling 3, 2, 1, and 2 consecutively because these are all values of 3 or less:
Programming Write a method named lucky that accepts an integer parameter min and rolls a 6-sided die until it gets four consecutive rolls in a row that have values of min or less. As the method rolls the die it should print each value rolled, and then it should print a message at the end to indicate how many rolls were made. For example, the call of lucky(3); should print output such as the following (though the output would be different on every call because of randomness). Notice that the method stops after rolling 3, 2, 1, and 2 consecutively because these are all values of 3 or less:    5 2 4 6 1 3 5 5 3 2 1 2 Finished after 12 rolls. A call of lucky(5); should print output such as the following. Notice that it continues rolling until it rolls four consecutive dice rolls produce a value of 5 or less. In this example, those values are 3, 5, 5, and 4. 1 3 6 3 5 5 4 Finished after 7 rolls. You may assume that the parameter value passed will be between 1 and 6 inclusive. 5 2 4 6 1 3 5 5 3 2 1 2
Finished after 12 rolls.
A call of lucky(5); should print output such as the following. Notice that it continues rolling until it rolls four consecutive dice rolls produce a value of 5 or less. In this example, those values are 3, 5, 5, and 4.
1 3 6 3 5 5 4
Finished after 7 rolls.
You may assume that the parameter value passed will be between 1 and 6 inclusive.


Definitions:

Narcissistic

Pertaining to a personality trait characterized by excessive self-love, a need for admiration, and a lack of empathy for others.

Spotlight Effect

The tendency to overestimate the extent to which one's actions and appearance are noted by others.

Inferiority Complex

A psychological condition that exists when a person feels inferior to others in some way, leading to lowered self-esteem and confidence.

Weak Superego

A term in Freudian psychoanalysis referring to an underdeveloped superego, which results in difficulty controlling impulses and adhering to societal norms and morals.

Related Questions