Results 1 to 3 of 3

Thread: Please help

  1. #1
    Boobikins is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Unhappy 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:

    Java 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

  2. #2
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    Ehh, Idk about these square types, but what I notice is this:
    Java 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.
    Java Code:
    background = bg;
       background.setLength(75);
    Thats what I think you ment to do..

  3. #3
    Boobikins is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default

    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:

    Java 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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •