Page 1 of 5 123 ... LastLast
Results 1 to 20 of 83
  1. #1
    Thumper is offline Member
    Join Date
    Dec 2009
    Posts
    11
    Rep Power
    0

    Default [FIXED ]Illegal expression

    Hi all I'm fairly new to java and need a little bit of help, I'm getting an error of an Illegal expression when I compile my code, and can't see where it is:confused: I know its an error in the code like a bracket missing.

    Here's the part of the code where the error in appearing

    /**
    * 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);
    getTopLeftSpot = tL;
    getTopMiddleSpot = tM;
    getTopRightSpot = tR;
    getMiddleSpot = mid;
    getBottomLeftSpot = bL;
    getBottomMiddleSpot = bM;
    getBottomRightSpot = bR;
    this.reset();

    }

    /**
    * Instance method to change the change the face of the
    * dice, check first to make sure the number is in range
    * of 1 to 6, and alert if not in range.
    */

    public int changeFace(int n);
    {
    int n;
    if ((n >= 6) || (n <= 0))
    {
    OUDialog.alert("Argument to changeFace() message " + (n) +" is out of range");
    }
    else
    {
    return this.getFace(n);
    }

    /* instance methods */

    /**
    * Returns the receiver's background
    */
    public Square getBackground()
    {
    return background;
    }
    It's when it gets to public Square getBackground, when the error appears

    Thanks
    Last edited by Thumper; 12-07-2009 at 04:00 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I wonder if you are having a problem with capitalization since Java is cAsE sensitive. Let's see the entire class.

  3. #3
    Thumper is offline Member
    Join Date
    Dec 2009
    Posts
    11
    Rep Power
    0

    Default

    It could be that, I been staring at it and still can't just see it:)

    import ou.*;
    import java.util.Random;

    /**
    * Instances of class Dice simulate a playing dice. From outside an instance
    * of the class, the only messages that should be sent to a Dice object
    * in normal usage is rollDice() and reset().
    *
    * @author M255 CT
    * @version 1.0
    */
    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);
    getTopLeftSpot = tL;
    getTopMiddleSpot = tM;
    getTopRightSpot = tR;
    getMiddleSpot = mid;
    getBottomLeftSpot = bL;
    getBottomMiddleSpot = bM;
    getBottomRightSpot = bR;
    this.reset();

    }

    /**
    * Instance method to change the change the face of the
    * dice, check first to make sure the number is in range
    * of 1 to 6, and alert if not in range.
    */

    public int changeFace(int n);
    {
    int n;
    if ((n >= 6) || (n <= 0))
    {
    OUDialog.alert("Argument to changeFace() message " + (n) +" is out of range");
    }
    else
    {
    return this.getFace(n);
    }

    /* instance methods */




    /**
    * Returns the receiver's background
    */
    public Square getBackground()
    {
    return background;
    }


    /**
    * Returns the receiver's topLeftSpot
    */
    public Circle getTopLeftSpot()
    {
    return topLeftSpot;
    }


    /**
    * Returns the receiver's topMiddleSpot
    */
    public Circle getTopMiddleSpot()
    {
    return topMiddleSpot;
    }


    /**
    * Returns the receiver's topRightSpot
    */
    public Circle getTopRightSpot()
    {
    return topRightSpot;
    }


    /**
    * Returns the receiver's middleSpot
    */
    public Circle getMiddleSpot()
    {
    return middleSpot;
    }


    /**
    * Returns the receiver's bottomLeftSpott
    */
    public Circle getBottomLeftSpot()
    {
    return bottomLeftSpot;
    }


    /**
    * Returns the receiver's bottomMiddleSpot
    */
    public Circle getBottomMiddleSpot()
    {
    return bottomMiddleSpot;
    }


    /**
    * Returns the receiver's bottomRightSpot
    */
    public Circle getBottomRightSpot()
    {
    return bottomRightSpot;
    }




    /**
    * Sets the x position of the background and the x/y positions of the
    * seven spots so that they are distributed over the square in the
    * familiar dice pattern. Finally the method sets the face
    * of the dice to 1 spot.
    */
    public void reset()
    {
    this.getBackground().setXPos(0);
    this.getTopLeftSpot().setXPos(3);
    this.getTopLeftSpot().setYPos(3);
    this.getTopMiddleSpot().setXPos(25);
    this.getTopMiddleSpot().setYPos(3);
    this.getTopRightSpot().setXPos(48);
    this.getTopRightSpot().setYPos(3);
    this.getMiddleSpot().setXPos(25);
    this.getMiddleSpot().setYPos(25);
    this.getBottomLeftSpot().setXPos(3);
    this.getBottomLeftSpot().setYPos(48);
    this.getBottomMiddleSpot().setXPos(25);
    this.getBottomMiddleSpot().setYPos(48);
    this.getBottomRightSpot().setXPos(48);
    this.getBottomRightSpot().setYPos(48);
    this.face1();
    }


    /**
    * Sets the face of the receiver to 1 spot
    */
    public void face1()
    {
    this.getTopLeftSpot().setColour(OUColour.ORANGE);
    this.getTopMiddleSpot().setColour(OUColour.ORANGE) ;
    this.getTopRightSpot().setColour(OUColour.ORANGE);
    this.getMiddleSpot().setColour(OUColour.BLUE);
    this.getBottomLeftSpot().setColour(OUColour.ORANGE );
    this.getBottomMiddleSpot().setColour(OUColour.ORAN GE);
    this.getBottomRightSpot().setColour(OUColour.ORANG E);
    }


    /**
    * Sets the face of the receiver to 2 spots
    */
    public void face2()
    {
    this.getTopLeftSpot().setColour(OUColour.ORANGE);
    this.getTopMiddleSpot().setColour(OUColour.ORANGE) ;
    this.getTopRightSpot().setColour(OUColour.BLUE);
    this.getMiddleSpot().setColour(OUColour.ORANGE);
    this.getBottomLeftSpot().setColour(OUColour.BLUE);
    this.getBottomMiddleSpot().setColour(OUColour.ORAN GE);
    this.getBottomRightSpot().setColour(OUColour.ORANG E);
    }


    /**
    * Sets the face of the receiver to 3 spots
    */
    public void face3()
    {
    this.getTopLeftSpot().setColour(OUColour.ORANGE);
    this.getTopMiddleSpot().setColour(OUColour.ORANGE) ;
    this.getTopRightSpot().setColour(OUColour.BLUE);
    this.getMiddleSpot().setColour(OUColour.BLUE);
    this.getBottomLeftSpot().setColour(OUColour.BLUE);
    this.getBottomMiddleSpot().setColour(OUColour.ORAN GE);
    this.getBottomRightSpot().setColour(OUColour.ORANG E);
    }


    /**
    * Sets the face of the receiver to 4 spots
    */
    public void face4()
    {
    this.getTopLeftSpot().setColour(OUColour.BLUE);
    this.getTopMiddleSpot().setColour(OUColour.ORANGE) ;
    this.getTopRightSpot().setColour(OUColour.BLUE);
    this.getMiddleSpot().setColour(OUColour.ORANGE);
    this.getBottomLeftSpot().setColour(OUColour.BLUE);
    this.getBottomMiddleSpot().setColour(OUColour.ORAN GE);
    this.getBottomRightSpot().setColour(OUColour.BLUE) ;
    }


    /**
    * Sets the face of the receiver to 5 spots
    */
    public void face5()
    {
    this.getTopLeftSpot().setColour(OUColour.BLUE);
    this.getTopMiddleSpot().setColour(OUColour.ORANGE) ;
    this.getTopRightSpot().setColour(OUColour.BLUE);
    this.getMiddleSpot().setColour(OUColour.BLUE);
    this.getBottomLeftSpot().setColour(OUColour.BLUE);
    this.getBottomMiddleSpot().setColour(OUColour.ORAN GE);
    this.getBottomRightSpot().setColour(OUColour.BLUE) ;
    }


    /**
    * Sets the face of the receiver to 6 spots
    */
    public void face6()
    {
    this.getTopLeftSpot().setColour(OUColour.BLUE);
    this.getTopMiddleSpot().setColour(OUColour.BLUE);
    this.getTopRightSpot().setColour(OUColour.BLUE);
    this.getMiddleSpot().setColour(OUColour.ORANGE);
    this.getBottomLeftSpot().setColour(OUColour.BLUE);
    this.getBottomMiddleSpot().setColour(OUColour.BLUE );
    this.getBottomRightSpot().setColour(OUColour.BLUE) ;
    }


    /**
    * Causes execution to pause by time number of milliseconds
    */
    private void delay(int time)
    {
    try
    {
    Thread.sleep(time);
    }
    catch (Exception e)
    {
    System.out.println(e);
    }
    }


    }

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,173
    Rep Power
    20

    Default

    You define "background" as a Square at the top of the class, but in the first line of the constructor you're using "Background".

    Also, you need to post in code tags, not quotes, otherwise any formatting gets removed.

    And finally, what exactly is the error you're getting. And indicate the line it happens on.

  5. #5
    Join Date
    Mar 2008
    Posts
    6
    Rep Power
    0

    Default

    I think you may miss closing braces of any method.

  6. #6
    tinman is offline Member
    Join Date
    Dec 2009
    Posts
    5
    Rep Power
    0

    Default

    If you need some help thumper PM me mate

  7. #7
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Default

    Change face is missing the closing bracket.

    public int changeFace(int n); <- nix the semi-colon
    { b1-o
    int n;
    if ((n >= 6) || (n <= 0))
    { b2-0
    OUDialog.alert("Argument to changeFace() message " + (n) +" is out of range");
    } b2-c
    else
    { b3-o
    return this.getFace(n);
    } b3-c

    no b1-c
    /* instance methods */




    /**
    * Returns the receiver's background
    */
    public Square getBackground()
    {
    return background;
    }

    Ex LISP programmer.
    Last edited by rdtindsm; 12-08-2009 at 09:18 AM.

  8. #8
    AliM is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default

    Hi All, another newb here! I've tried to PM the OP as I think i'm doing the same thing as they are and thought we may be able to help each other, but my post count isn't high enough to PM yet? so I am really sorry for the thread hijack!

    I'm working on public int changeFace(int n)
    If the value of n is 1- 6 inclusive, the method should send a 'face' message to the reciever 'this'. i,e if the value of n is 3 the method should send face3() to the reciever and change the dice.

    Would the code that the OP has written acheive that? getFace() hasn't been declared anywhere so the code errors when you try to compile it.

    I was thinking that I should be using an if statement for each value? for example:

    if (n==3)
    {
    return this.face3()
    }


    or am i just over complicating things? Any help would be much appreciated,

    thank you,
    Ali. :)

  9. #9
    kyussy is offline Member
    Join Date
    Dec 2009
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by AliM View Post
    Hi All, another newb here! I've tried to PM the OP as I think i'm doing the same thing as they are and thought we may be able to help each other, but my post count isn't high enough to PM yet? so I am really sorry for the thread hijack!

    I'm working on public int changeFace(int n)
    If the value of n is 1- 6 inclusive, the method should send a 'face' message to the reciever 'this'. i,e if the value of n is 3 the method should send face3() to the reciever and change the dice.

    Would the code that the OP has written acheive that? getFace() hasn't been declared anywhere so the code errors when you try to compile it.

    I was thinking that I should be using an if statement for each value? for example:

    if (n==3)
    {
    return this.face3()
    }


    or am i just over complicating things? Any help would be much appreciated,

    thank you,
    Ali. :)
    Hi Ali,
    I'm working on the same thing and I just used a nested if table with the format if n == 1 then this.method1(); before that I used a Boolean to disregard anything out of range and send an alert. Not sure if this the best way to do it, but it works ;)

    the next bit has been driving me mental though - I just can't get the square to move, even though the inspector say it has. Any ideas?

  10. #10
    humdinger is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Default

    Hi all im also working on this. if you want to speak to me about this contact me via email and we could possibly help each other as I have finished this part but im stuck on another part

  11. #11
    Oli2uok is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default This course too

    Im really struggling on this one too!!

    Any ideas humdinger??

    cheers Oli

  12. #12
    gcampton Guest

    Default

    Did the course instructor instruct everyone to come here?

    Geez I stumbled here by mistake one day, normally teachers tell you to stay away from internet as it confuses things, stick to the text and their notes and they usually won't lead you astray.

  13. #13
    Oli2uok is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default Guildance

    Was just looking for guidance not full answers!!

    Oli.

  14. #14
    Oli2uok is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default ideas

    Quote Originally Posted by humdinger View Post
    Hi all im also working on this. if you want to speak to me about this contact me via email and we could possibly help each other as I have finished this part but im stuck on another part

    Any Ideas would help. cheers

  15. #15
    tinman is offline Member
    Join Date
    Dec 2009
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Oli2uok View Post
    Any Ideas would help. cheers
    same here im up to (iv) (a) pretty much stuck here anyone any further???

  16. #16
    Oli2uok is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default

    Im stuck on (ii) if you have any ideas!! lol

  17. #17
    Oli2uok is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default Ideas!!

    Quote Originally Posted by tinman View Post
    same here im up to (iv) (a) pretty much stuck here anyone any further???
    Im stuck on (ii) if you have any ideas!! lol

  18. #18
    tinman is offline Member
    Join Date
    Dec 2009
    Posts
    5
    Rep Power
    0

    Default

    I need to make a few post to ps you, but what are you stuck with?????

  19. #19
    gcampton Guest

    Default

    if you post some specific questions others on here may be able to help.
    Last edited by gcampton; 12-09-2009 at 01:27 AM.

  20. #20
    kyussy is offline Member
    Join Date
    Dec 2009
    Posts
    10
    Rep Power
    0

    Default

    I've now pretty much manged to finish this one now. I still have to finish the Boolean part of Q4(v), which (hopefully) I'll get done tomorrow.:)

    Apart from that damn moveBackground() (why won't the square move?WHY?) the xpos changes, the spots are fine. It's so annoying, I know it will be something pissy I have overlooked as well.

    Let me know if I can help

Page 1 of 5 123 ... LastLast

Similar Threads

  1. Illegal Start of expression
    By Macca07 in forum New To Java
    Replies: 3
    Last Post: 11-23-2009, 09:43 AM
  2. Illegal start of expression
    By Basit56 in forum New To Java
    Replies: 2
    Last Post: 08-18-2009, 10:12 AM
  3. Illegal Start of an Expression
    By David55 in forum CLDC and MIDP
    Replies: 8
    Last Post: 11-02-2007, 10:11 PM
  4. Illegal start of expression
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 06:09 PM
  5. Illegal Start of an Expression
    By David55 in forum CLDC and MIDP
    Replies: 0
    Last Post: 04-20-2007, 06:59 AM

Posting Permissions

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