View Full Version : Java Dice Program.

03-25-2008, 09:10 PM
Hello all, I'm writing a program essentially for the following.

Instances of the Dice class model a playing dice. The Dice class will have six sides with zero, 1, 2, 3, 4, and 5 spots.

An instance of Dice is made up of an orange square and
5circles. Different numbers of circles are either orange or blue depending on which ‘side’ of the dice is facing whoever uses this program..

So for example the ‘side’ of the dice with 5 spots is graphically represented as an orange square with 5 blue circles.

The face of the dice with two spots is graphically represented as an orange square with two blue circles and three orange circles, which cannot be seen against an orange background.

The constructor is called with six arguments: a square and the five
circles that are assigned to six of the instance variables. In addition the square is set to a length of 75. None of the instance variables have accessor methods as only instances of the class need access to them and there is no intention to change the implementation of the attributes.

I need to directly access these instance variables when you need to get or set their values.

All the circles that are referenced by the instance variables topLeft, bottomLeft, middle, topRight and bottomRight have their xPos and yPos set to the default of 0.

I've gotten to the following so far.

public class Dice
/* instance variables */
private Square sq;
private Circle topLeft;
private Circle bottomLeft;
private Circle middle;
private Circle topRight;
private Circle bottomRight;
private Random ran = new Random();
private int xPos;
private int yPos;

* Constructor for objects of class Dice
public Dice(Square s, Circle tL, Circle bL, Circle mid, Circle tR, Circle bR)
this.sq = s;
this.topLeft = tL;
this.bottomLeft = bL;
this.middle = mid;
this.topRight = tR;
this.bottomRight = bR;

/* instance methods */
/**Sets the positions of the dots to Figure 2
public void initialiseSpots()
int xPos;
int yPos;
xPos = 0;
yPos = 0;
int setLocation(xPos,yPos);
* Sets the side of the receiver to 0 spots
public void side0()

* Changes the side of the receiver to either 0, 1, 3, 3, 4 or 5
* spots depending on the value of the argument.

I'm not sure how to deal with the method to have the circles appear as it's needed, so if anybody could give me a hand, that would be grand.