-
Please help
I'm trying to get a dice programme to work. Basically I need to create a square of length 75 with spots to represent a dice.
For some reason, the square length is always 20, the same as the dots, so it doesn't look like a dice. The code I have is as follows:
Code:
public class Dice
{
/* instance variables */
private Square background;
private Circle topLeftSpot;
private Circle topMiddleSpot;
private Circle topRightSpot;
private Circle middleSpot;
private Circle bottomLeftSpot;
private Circle bottomMiddleSpot;
private Circle bottomRightSpot;
/**
* Constructor for objects of class Dice
*/
public Dice(Square bg, Circle tL, Circle tM, Circle tR, Circle mid, Circle bL, Circle bM, Circle bR)
{
background = bg;
bg.setLength(75);
topLeftSpot = tL;
topMiddleSpot = tM;
topRightSpot = tR;
middleSpot = mid;
bottomLeftSpot = bL;
bottomMiddleSpot = bM;
bottomRightSpot = bR;
this.reset();
}
Please can someone help?!?!?!
Thanks in advance
-
Ehh, Idk about these square types, but what I notice is this:
Code:
background = bg;
bg.setLength(75);
I assume what you call background is not bg, but background
If thats the case then your currently doing this:
First you set Background to be just like bg is.
Then you change bg, but this doesnt automaticly change background.
Code:
background = bg;
background.setLength(75);
Thats what I think you ment to do..
-
The question was :
write a new contructor for the Dice class and then write a new constructor for the Dice class with the following header:
public Dice(Square bg, Circle tL, Circle tM, Circle tR, Circle mid, Circle bL, Circle bM, Circle bR)
The constructor should do the following. First it should send message to the Square object referenced by the argument bg to set its length to 75. Then tell all the arguments of the constructor should be directly assigned to the appropriate instance variables. Finally a reset() message shoud be sent to this (the receiver).
The section below was already given:
Code:
public class Dice
{
/* instance variables */
private Square background;
private Circle topLeftSpot;
private Circle topMiddleSpot;
private Circle topRightSpot;
private Circle middleSpot;
private Circle bottomLeftSpot;
private Circle bottomMiddleSpot;
private Circle bottomRightSpot;
Thanks!