Imagine that you want to display the upper face of a die for a particular game. Suppose you define a class Die to represent a die face and use an array of seven Dot objects to represent the dots on the face. Each Dot object has a position, and they are arranged on a square as follows:
Each Dot object also has a method to make it either visible or invisible. After generating a random integer between 1 and 6 to simulate the roll of the die, you would make the appropriate dot or dots visible, thereby displaying the die’s upper face as one of the previous configurations. Since the Dot objects are in an array, you should arrange them so that visible dots are in adjacent elements of the array. Then you can use a loop (or loops) to display the dots on the die’s face. To this end, number the positions of the dots on the die face from 0 to 6.
Define the classes Dot and Die, as well as a driver that demonstrates the behavior of your classes.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here