Question: Design and create a Dice class, which has below methods: 1. A constructor that receives dices minimum value and maximum value as the parameters. 2.
Design and create a Dice class, which has below methods:
1. A constructor that receives dices minimum value and maximum value as the parameters. 2. A static method displayCount that displays the total number of dices that have been created. 3. A roll method that roll the dice, generate and store a number that is between the dice's minimum and maximum value (inclusive). Below codes can be used to generate an integer number between minVal and maxVal (inclusive): import random i= random.randint(minVal, maxVal)
4. A getCurrentNumber method that returns the latest generated number.
5. A reset method that reset the dice as if it is has just been newly created..
6. A __str__ method which returns a string that show the dice's minimum value, maximum value, how many times the dice has been rolled, and the sequence of numbers that have been generated so far.
7. Aa __mul__ operator that receives a scalar value that indicates how many times the dice needs to be rolled, and returns the total summation of the generated values.
8. An __add__ operator that receives another dice as parameter, starts rolling current dice and that another dice, to generate a pair of new values and returns the total summation of those two newly generated values.


Please I need it asap
Example of how above methods are used is illustrated below: di = Dice (1,6) d2 = Dice (1,12) Dice.displayDiceCount() # "Total Dice created: 2" is displayed print (dl) # "Dice has max value of 1 and min value of 6 # and has been rolled 0 times. # The numbers generated so far are []" is displayed. dl.roll() print (d.getCurrentNumber()) # "3" is displayed. print (dl) # "Dice has max value of 1 and min value of 6 # and has been rolled 1 times. # The numbers generated so far are [3]" is displayed. dl.reset() print (dl) # "Dice has max value of 1 and min value of 6 # and has been rolled 0 times. # The numbers generated so far are []" is displayed. s = dl * 2 print (s) # "9" is displayed print (dl) # "Dice has max value of 1 and min value of 6 S and has been rolled 2 times. # The numbers generated so far are [4, 5]" is displayed. = dl + d2 print (s) # "9" is displayed print (dl) # "Dice has max value of 1 and min value of 6 # and has been rolled 3 times. # The numbers generated so far are [4, 5, 1]" is displayed. print (d2) # "Dice has max value of 1 and min value of 12 # and has been rolled 1 times. # The numbers generated so far are [8]" is displayed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
