kyle mcguinness kyle mcguinness - 27 days ago 11
Java Question

I am trying to create a computer that uses the robot class to play freeze tag

while(computerIsFrozen==false)
{
while(computerIsTagger==true)
{
if(nextToARobot)
{
playerIsFrozen = true;
computerIsTagger = false;

}
}

if(computerIsFrozen==true)
{
for(int k=1; k<=8; k++)
{
turnLeft();
}
computerIsTagger = true;
computerIsFrozen = false;
}
}



I'm getting this error:

Computer.java:15: error: illegal start of type
while(computerIsFrozen==false)
^
Computer.java:15: error: <identifier> expected
while(computerIsFrozen==false)


why am I getting the error
illegal start of type on the first line
and also
identifier expected on the first line
. There also might be some more errors that I am not sure of.
computerIsFrozen
is initialized to false and so is
computerIsTagger
.

Answer

   while(computerIsFrozen==false)
   {
      while(computerIsTagger==true)
      {
         if(nextToARobot)
         {
         playerIsFrozen = true;
         computerIsTagger = false;
      
      }
   }  // <-- remove this curly brace
   
   
   if(computerIsFrozen==true)
   {
      for(int k=1; k<=8; k++)
      {
      turnLeft();
      }
   computerIsTagger = true;
   computerIsFrozen = false;
   }
} 
​