Results 1 to 4 of 4
  1. #1
    hsustudent is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Karel the robot issues

    I have written a code for my comp sci class and i'm nearly 100% sure the code does not do what i need it to do. :p
    But when i try to run the program, to see what kind of adjustments i need to make, it gives me three errors.
    When i check out what the errors are i cant find a problem with the line its pointing me to.
    The errors are:

    Description Resource Path Location Type
    Syntax error, insert "}" to complete ClassBody DemocracyKarel.java /ProgrammingAssignment1 line 67 Java Problem

    Description Resource Path Location Type
    Syntax error, insert "enum Identifier" to complete EnumHeaderName DemocracyKarel.java /ProgrammingAssignment1 line 67 Java Problem

    Description Resource Path Location Type
    Syntax error, insert "EnumBody" to complete EnumDeclaration DemocracyKarel.java /ProgrammingAssignment1 line 67 Java Problem


    Line 67 is the very last line of code. The only thing on that line is the closing bracket for the class body that the first error is telling i need to insert.

    I have gone over all the code to make sure I didn't forget another closing bracket somewhere and i cant find anything missing. Any help i can on this would be great!



    Java Code:
    import stanford.karel.*;
    
    public class DemocracyKarel extends SuperKarel
    {
    	/* Provides an entry point for Karel to begin execution of commands */
    	public void run()
    	{
    		while ( frontIsClear() )
    		{
    			if ( noBeepersPresent() )
    			{
    				move();
    				checkRectangle();
    			}
    		}	
    	}
    	
    	private void checkRectangle()
    	{
    		if ( noBeepersPresent() )
    		{
    			clearChad();
    		}
    		else
    		{
    			while ( frontIsClear() )
    			{
    				move();
    				move();
    			}
    		}
    	}	
    	
    	private void clearChad()
    	{
    		checkTop();
    		checkBottom();
    	}
    	
    	private void checkTop()
    	{
    		turnLeft();
    		move();
    		while ( beepersPresent() )
    		{
    			pickBeeper();
    		}
    		turnAround();
    	}
    
    
    	private void checkBottom()
    	{
    		move();
    		move();
    		if ( beepersPresent() )
    		{
    			pickBeeper();
    		}
    		else
    		{
    			turnAround();
    			move();
    			turnRight();
    		}
    	}
    }
    Last edited by hsustudent; 02-01-2012 at 11:28 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: Karel the robot issues

    it gives me three errors.
    What is the "it" that is giving the errors?

    Have you checked for the correct pairing of {}s?

  3. #3
    hsustudent is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: Karel the robot issues

    I am using Eclipse Helios for windows and yes I have check all the brackets to make sure they were paired properly.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: Karel the robot issues

    What errors do you get from the javac compiler?
    I don't recognize the error messages you posted.

    This code compiles for me with no errors:
    Java Code:
    public class DemocracyKarel { //extends SuperKarel
    
       // Dummy in missing methods
       boolean frontIsClear() {return true;}
       void move(){}
       void turnLeft(){}
       void turnRight(){}
       void turnAround(){}
       void pickBeeper(){}
       boolean beepersPresent() {return true;}
       boolean noBeepersPresent() {return true;}
    
        /* Provides an entry point for Karel to begin execution of commands */
        public void run()
        {
            while ( frontIsClear() )
            {
                if ( noBeepersPresent() )
                {
                    move();
                    checkRectangle();
                }
            }   
        }
         
        private void checkRectangle()
        {
            if ( noBeepersPresent() )
            {
                clearChad();
            }
            else
            {
                while ( frontIsClear() )
                {
                    move();
                    move();
                }
            }
        }   
         
        private void clearChad()
        {
            checkTop();
            checkBottom();
        }
         
        private void checkTop()
        {
            turnLeft();
            move();
            while ( beepersPresent() )
            {
                pickBeeper();
            }
            turnAround();
        }
     
     
        private void checkBottom()
        {
            move();
            move();
            if ( beepersPresent() )
            {
                pickBeeper();
            }
            else
            {
                turnAround();
                move();
                turnRight();
            }
        }
    }
    Last edited by Norm; 02-02-2012 at 11:20 PM.

Similar Threads

  1. Karel the robot: errors during run
    By neu_mann in forum New To Java
    Replies: 14
    Last Post: 06-17-2012, 05:12 AM
  2. Replies: 1
    Last Post: 12-07-2011, 08:39 PM
  3. karel the robot - are methods case sensitive?
    By Roee Yossef in forum New To Java
    Replies: 1
    Last Post: 11-07-2011, 09:23 AM
  4. Replies: 3
    Last Post: 07-19-2011, 09:41 PM
  5. Karel the robot
    By vulerious in forum New To Java
    Replies: 0
    Last Post: 07-31-2009, 10:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •