Results 1 to 20 of 83
Thread: Illegal expression
- 12-06-2009, 03:43 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 11
- Rep Power
- 0
[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
It's when it gets to public Square getBackground, when the error appears/**
* 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;
}
ThanksLast edited by Thumper; 12-07-2009 at 03:00 PM.
-
I wonder if you are having a problem with capitalization since Java is cAsE sensitive. Let's see the entire class.
- 12-06-2009, 04:13 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 11
- Rep Power
- 0
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);
}
}
}
- 12-07-2009, 09:41 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 12-07-2009, 10:21 AM #5
Member
- Join Date
- Mar 2008
- Posts
- 6
- Rep Power
- 0
I think you may miss closing braces of any method.
- 12-07-2009, 11:10 PM #6
Member
- Join Date
- Dec 2009
- Posts
- 5
- Rep Power
- 0
If you need some help thumper PM me mate
- 12-08-2009, 08:12 AM #7
Member
- Join Date
- Feb 2009
- Posts
- 92
- Rep Power
- 0
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 08:18 AM.
- 12-08-2009, 03:15 PM #8
Member
- Join Date
- Dec 2009
- Posts
- 3
- Rep Power
- 0
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. :)
- 12-08-2009, 04:39 PM #9
Member
- Join Date
- Dec 2009
- Posts
- 10
- Rep Power
- 0
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?
- 12-08-2009, 06:57 PM #10
Member
- Join Date
- Dec 2009
- Posts
- 1
- Rep Power
- 0
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
- 12-08-2009, 08:51 PM #11
Member
- Join Date
- Dec 2009
- Posts
- 20
- Rep Power
- 0
This course too
Im really struggling on this one too!!
Any ideas humdinger??
cheers Oli
- 12-08-2009, 10:00 PM #12gcampton Guest
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.
- 12-08-2009, 10:48 PM #13
Member
- Join Date
- Dec 2009
- Posts
- 20
- Rep Power
- 0
Guildance
Was just looking for guidance not full answers!!
Oli.
- 12-08-2009, 11:33 PM #14
Member
- Join Date
- Dec 2009
- Posts
- 20
- Rep Power
- 0
- 12-08-2009, 11:38 PM #15
Member
- Join Date
- Dec 2009
- Posts
- 5
- Rep Power
- 0
- 12-08-2009, 11:55 PM #16
Member
- Join Date
- Dec 2009
- Posts
- 20
- Rep Power
- 0
Im stuck on (ii) if you have any ideas!! lol
- 12-08-2009, 11:57 PM #17
Member
- Join Date
- Dec 2009
- Posts
- 20
- Rep Power
- 0
- 12-09-2009, 12:17 AM #18
Member
- Join Date
- Dec 2009
- Posts
- 5
- Rep Power
- 0
I need to make a few post to ps you, but what are you stuck with?????
- 12-09-2009, 12:18 AM #19gcampton Guest
if you post some specific questions others on here may be able to help.
Last edited by gcampton; 12-09-2009 at 12:27 AM.
- 12-09-2009, 12:19 AM #20
Member
- Join Date
- Dec 2009
- Posts
- 10
- Rep Power
- 0
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
Similar Threads
-
Illegal Start of expression
By Macca07 in forum New To JavaReplies: 3Last Post: 11-23-2009, 08:43 AM -
Illegal start of expression
By Basit56 in forum New To JavaReplies: 2Last Post: 08-18-2009, 09:12 AM -
Illegal Start of an Expression
By David55 in forum CLDC and MIDPReplies: 8Last Post: 11-02-2007, 09:11 PM -
Illegal start of expression
By gabriel in forum New To JavaReplies: 2Last Post: 08-01-2007, 05:09 PM -
Illegal Start of an Expression
By David55 in forum CLDC and MIDPReplies: 0Last Post: 04-20-2007, 05:59 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks