Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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



Report this thread to moderator Post Follow-up to this message
Old Post
ms
12-24-04 02:06 PM


Re: Error: orphaned case
"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.



Report this thread to moderator Post Follow-up to this message
Old Post
Ryan Stewart
12-24-04 02:06 PM


Re: Error: orphaned case
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.

:)

Report this thread to moderator Post Follow-up to this message
Old Post
Lew Bloch
12-28-04 08:57 AM


Re: Error: orphaned case
"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.



Report this thread to moderator Post Follow-up to this message
Old Post
Ryan Stewart
12-28-04 08:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:29 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.