Posted: Mon Nov 2
Due: Wednesday 11/4 10:00am
Submission name: w20_dice
Create a Die Class
classDiagram
class Die {
-int x
-int y
-int dsize
-int value
+Die(int x, int y, int s)
+void display()
+void roll()
}
- Constructor:
- Takes 3 arguments representing the (x, y) position and size of the Die.
- Sets the value to a random integer in the range [1, 6].
void display()- Draws the die as a square with the
valueinside the die as text. Use the image below as your guide.
- Draws the die as a square with the
void roll()- Sets the
valueof the die to a new integer in the range [1, 6]
- Sets the

Die d0, d1;
void setup() {
size(200, 200);
d0 = new Die(25, height/2 - 25, 50);
d1 = new Die(125, height/2 - 25, 50);
}//setup
void draw() {
background(150);
d0.display();
d1.display();
}//draw
void keyPressed() {
if (key == ' ') {
d0.roll();
d1.roll();
}//roll
}//if keyPressed
Optional Additions
If you get all this working, here are some things you could try:
- Add the capability to modify the number of sides a
Diecould have. - Instead of displaying a number, display “pips” (the little circles on a standard die).
- Other visual flair.