This site requires JavaScript, please enable it in your browser!
Greenfoot back
Anonymous123
Anonymous123 wrote ...

2020/6/7

cant figure out why my it says reached end of file while parsing

Anonymous123 Anonymous123

2020/6/7

#
Anonymous123 Anonymous123

2020/6/7

#
import greenfoot.*;
/**
 * A Rover is a drone that likes is programmed with a generic algorithm to find and collect space tomatoes.
 * The programming can be updated remotely to improve the collection algorithm for whatever planet the rovers are deployed to.
 * 
 * @author (your name here)
 * @version 0.2
 */
public class Rover extends Bot
    {
    // Remember: you cannot extend the Rover's memory. So:
    // no additional fields (other than final fields) allowed in this class!
    
    /**
     * Default constructor for testing purposes.
     */
    public Rover()
    {
        this(null);
    }
    
    /**
     * Create a Rover with its home space ship.
     */
    public Rover(Ship ship)
    {
        super(ship);
    }

    /**
     * Do what a rover does.
     * Most of your coding will take place in this method. You can create additional methods if needed, but you can't change any other methods.
     * (apart from modifying one line in getAuthorName() below)
     */
    public void act()
    {
        {
    {
        super.act();   // do not delete! leave as first statement in act().
        if (carryingTomato()) {
            if (atShip()) {
                dropTomato();
            }
            if (carryingTomato()) {
            if (atWater()){
                turn(90);
                move(2);
            }
            else {
                turnHome();
                move();
            }
            while(rover!= end_point)
                if(roverhits_water);
                turn (90);
            {    
              while(rover!=end_point)
              if(roverhits_water)
              turn (90);

        }
        
    }
     
      }      
    }      
    }
    
    /**
     * Is there any food here where we are? If so, try to load some!
     */
    {
    Public_void (checkFood);
    {
         {
        // check whether there's a tomato pile here
        TomatoPile tomatoes = (TomatoPile) getOneIntersectingObject(TomatoPile.class);
        if (tomatoes != null) {
            loadTomato();
            if (carryingTomato()) {
                turnHome();
                    turnHome();
                    move();
            }
            // Note: this attempts to load a tomato onto *another* Rover. It won't
            // do anything if we are alone here.
        }
    }

    /**
     * This method specifies the name of the author (for display on the result board).
     */
    Public_static String_getAuthorName;
    {
        return "Anonymous";  //ENTERNAMEHERE
    }
    
    {   
    /**
     * This method specifies the image we want displayed at any time. (No need 
     * to change this for the competition.)
     */

    Public_String_getCurrentImage();
    {
        if (carryingTomato()) {
            return "rover-with-food.gif";
       }
        else {
            return "rover.gif";
        }
    }
}
Anonymous123 Anonymous123

2020/6/7

#
my code doesn't work. it says that it reached the end of the file while parsing. if anyone can help that would be helpful. Cheers, Corey
danpost danpost

2020/6/7

#
Go through your code and make sure your brackets are paired up properly. Use Ctrl-Shift-I to auto-layout so you can see at what level of depth each line is at. Turn unwanted double pairs into single pairs. The parsing error should no longer appear once the brackets, "{' and '}', are paired up correctly.
Anonymous123 Anonymous123

2020/6/7

#
thanks
Anonymous123 Anonymous123

2020/6/8

#
still doesn't work and i don't know why. I have showed my teacher and he said it should work. The curly brackets match up in every file.
danpost danpost

2020/6/8

#
Anonymous123 wrote...
still doesn't work and i don't know why. I have showed my teacher and he said it should work. The curly brackets match up in every file.
I've corrected what mistakes I could find (quite a few -- unwanted brackets, capitalized "public"s, unwanted underscores, invalid method declaration).
import greenfoot.*;
/**
 * A Rover is a drone that likes is programmed with a generic algorithm to find and collect space tomatoes.
 * The programming can be updated remotely to improve the collection algorithm for whatever planet the rovers are deployed to.
 * 
 * @author (your name here)
 * @version 0.2
 */
public class Rover extends Bot
{
    // Remember: you cannot extend the Rover's memory. So:
    // no additional fields (other than final fields) allowed in this class!

    /**
     * Default constructor for testing purposes.
     */
    public Rover()
    {
        this(null);
    }

    /**
     * Create a Rover with its home space ship.
     */
    public Rover(Ship ship)
    {
        super(ship);
    }

    /**
     * Do what a rover does.
     * Most of your coding will take place in this method. You can create additional methods if needed, but you can't change any other methods.
     * (apart from modifying one line in getAuthorName() below)
     */
    public void act()
    {
        super.act();   // do not delete! leave as first statement in act().
        if (carryingTomato())
        {
            if (atShip()) 
            {
                dropTomato();
            }
            if (carryingTomato()) 
            {
                if (atWater())
                {
                    turn(90);
                    move(2);
                }
                else
                {
                    turnHome();
                    move();
                }
                while(rover!= end_point) if(roverhits_water) ;
                turn (90);
                {    
                    while(rover!=end_point) if(roverhits_water) turn (90);
                }
            }
        }
    }

    /**
     * Is there any food here where we are? If so, try to load some!
     */
    public void checkFood()
    {
        // check whether there's a tomato pile here
        TomatoPile tomatoes = (TomatoPile) getOneIntersectingObject(TomatoPile.class);
        if (tomatoes != null)
        {
            loadTomato();
            if (carryingTomato())
            {
                turnHome();
                turnHome();
                move();
            }
            // Note: this attempts to load a tomato onto *another* Rover. It won't
            // do anything if we are alone here.
        }
    }

    /**
     * This method specifies the name of the author (for display on the result board).
     */
    public static String getAuthorName;
    {
        return "Anonymous";  //ENTERNAMEHERE
    }

    /**
     * This method specifies the image we want displayed at any time. (No need 
     * to change this for the competition.)
     */

    public String getCurrentImage();
    {
        if (carryingTomato())
        {
            return "rover-with-food.gif";
        }
        else
        {
            return "rover.gif";
        }
    }
}
danpost danpost

2020/6/8

#
I am not sure about the logic between lines 56 and 60. Looks like an unwanted semi-colon as well as double coding. But, also, got to make sure the while condition will change (become false somewhere within the loop. I cannot be sure it will just by turning.
Anonymous123 Anonymous123

2020/6/9

#
Thanks it works now. However when i opened it again the last public the P was for some reason wrong. ill just fiddle with it for a few hours. Thanks for the help danpost. Have a great day, Cheers, anonymous123
You need to login to post a reply.