Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this message"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.
Post Follow-up to this messageRyan 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. :)
Post Follow-up to this message"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.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.