Create the following classes in Java: 1. Die with 6 faces (1,2,3,4,5,6): Behavior: - roll : randomly show one face 2. CustomDie : a die with custom faces, eg "nice", "naughty" - can be created by providing the custom faces. Additional Behaviors - addFace: adds a new face to the die - removeFace: removes the specified face from the die 3. UnfairDie : a custom die where faces have different chances of showing - an unfair die can be created by - providing the custom faces, assigning equal chances - providing the custom faces and chances, when chance values are invalid, assign equal chances - when adding or removing a face, faces will have equal chances Additional Behavior - setChances : uses the provided set of chance values for each face : when chances is invalid, retain old chances : assigns each chance for each face in order of addition Note: roll method must not be overridden on any subclass base class must be the Die class Invalid chances on unfair die means number of chance values does not match the number of faces or the sum of the chance values is not equal to 1. When it is impossible to assigning equal chances for the die, assign the excess chance to the last face.
Create the following classes in Java:
1. Die with 6 faces (1,2,3,4,5,6):
Behavior:
- roll : randomly show one face
2. CustomDie : a die with custom faces, eg "nice", "naughty"
- can be created by providing the custom faces.
Additional Behaviors
- addFace: adds a new face to the die
- removeFace: removes the specified face from the die
3. UnfairDie : a custom die where faces have different chances of showing
- an unfair die can be created by
- providing the custom faces, assigning equal chances
- providing the custom faces and chances, when chance values are invalid, assign equal chances
- when adding or removing a face, faces will have equal chances
Additional Behavior
- setChances : uses the provided set of chance values for each face
: when chances is invalid, retain old chances
: assigns each chance for each face in order of addition
Note:
- roll method must not be overridden on any subclass
- base class must be the Die class
- Invalid chances on unfair die means number of chance values does not match the number of faces or the sum of the chance values is not equal to 1.
- When it is impossible to assigning equal chances for the die, assign the excess chance to the last face.

Step by step
Solved in 4 steps with 4 images









