Home > Archive > Java Help > December 2004 > Error: orphaned case
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Error: orphaned case
|
|
|
| I get this error message in my switch statement, hope someone can help!
import java.awt.*;
class Animal
{ private int x_pos;
private int y_pos;
private int radius;
private static final int active = 0;
private static final int sleeping = 1;
private static final int tootired = 200;
private static final double sleepnow = tootired*0.9;
private static final double wakeupnow = tootired*0.1;
private int numberofticks;
private int state;
private int sleepiness;
private Habitat container;
public Animal(int x_initial, int y_initial, int r, Habitat hab)
{ x_pos = x_initial;
y_pos = y_initial;
radius = r;
container = hab;
state = active;
sleepiness = 0;
numberofticks=0;
}
public int xPosition()
{ return x_pos; }
public int yPosition()
{ return y_pos; }
public int radiusOf()
{ return radius; }
public void move()
{ boolean searching=true;
double sleepiness_score;
numberofticks++;
switch (state) {
case active:
if (numberofticks%10 == 0) sleepiness++;
sleepiness_score = Math.round(Math.random()*sleepiness);
if (sleepiness_score>sleepnow) {
state=sleeping;
}
while (searching) {
x_pos = x_pos + (int)Math.round(Math.random()*2-1);
y_pos = y_pos + (int)Math.round(Math.random()*2-1);
searching = (!container.inHorizontalContact(x_pos) &&
!container.inVerticalContact(y_pos));
break;
case sleeping:
if (numberofticks%10 == 0) sleepiness-=3;
sleepiness_score =
Math.round(Math.random()*(tootired-sleepiness))+sleepiness;
if (sleepiness_score<wakeupnow) {
state= active;
}
break;
}
}
}
}
JS
| |
| Ryan Stewart 2004-12-24, 9:06 am |
| "ms" <dsf@as.com> wrote in message
news:MuTyd.77365$Vf.3636675@news000.worldonline.dk...
>I get this error message in my switch statement, hope someone can help!
>
[...]
> switch (state) {
> case active:
[...]
> while (searching) {
[...]
> case sleeping:
[...]
> }
> }
Does that work? I think not.
| |
| Lew Bloch 2004-12-28, 3:57 am |
| Ryan Stewart wrote:
> "ms" <dsf@as.com> wrote in message
> news:MuTyd.77365$Vf.3636675@news000.worldonline.dk...
>
>
> [...]
>
>
> [...]
>
>
> [...]
>
>
> [...]
>
>
> Does that work? I think not.
A good example of why opening braces should go on their own line. The
mismatch would have been much more blatant.
:)
| |
| Ryan Stewart 2004-12-28, 3:57 am |
| "Lew Bloch" <justaguy@nospam.net> wrote in message
news:Ld-dnWKk242Mb03cRVn-3A@comcast.com...
> A good example of why opening braces should go on their own line. The
> mismatch would have been much more blatant.
>
> :)
Doubtful, as the indentation suggested the proper structure, but he, for
whatever reason, chose to move the closing brace somewhere else. Whatever
the case, I won't condone breaking the standards.
|
|
|
|
|