public class Mito extends Animal
{
/**
* Act - do whatever the Mito wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Problem#1
if (isAtEdge() )
{
turn(19);
}
move(2);
// Problem#3 The defined method I used is isAtEdge. The code I used it if (isAtEdge() 0 { turn(19);
//Problem #1
move(5);
if (Greenfoot.isKeyDown("a"))
{
turn(2);
}
move(2);
if (Greenfoot.isKeyDown("b"))
{
turn(5);
}
//Problem#2
move(1);
if (Greenfoot.isKeyDown("left"))
{
turn(-3);
}
if (Greenfoot.isKeyDown("right"))
{
turn(3);
}
//Problem # 3
if (Greenfoot.isKeyDown("x"))
{
Greenfoot.playSound("Boing.wav");
}
if (Greenfoot.isKeyDown("y"))
{
Greenfoot.playSound("Bam.wav");
}
}
public void eat()
{
Actor FishFoodPellets;
FishFoodPellets = getOneObjectAtOffset(0, 0, FishFoodPellets.class);
if (FishFoodPellets != null)
{
World world;
world = getWorld();
world.removeObject(FishFoodPellets);
}
}
public void lookForCode()
{
if (canSee(FishFoodPellets.class))
{
eat(FishFoodPellets.class);
Greenfoot.playSound("Chomp.wav");
}
}
/**
* Return true if Mito can see an object of the FishFoodPellets class. Return false if there is no FishFoodPellet object there.
*/
public boolean canSee (Class FishFoodPellets)
{
Actor FishFoodPellets = getOneObjectAtOffset(0, 0, FishFoodPellets.class);
return FishFoodPellets !=null;
}
/**
* Eat an object of class "FishFoodPellets" if there is such an object in our current location.
*/
public void eat(Class FishFoodPellets)
{
Actor FishFoodPellets = getOneObjectAtOffset(0, 0, FishFoodPellets.class);
if (FishFoodPellets != null) {
getWorld().removeObject(FishFoodPellets);
}
}
}
How do I fix the error: "Actor FishFoodPellets = getOneObjectAtOffset(0, 0, FishFoodPellets.class);"
Greenfoot says for the first one, "Variable FishFoodPellets is alread defined in method eat(java.lang.Class)" and the second one says, "Variable FishFoodPellets is alread defined in method canSee(java.lang.class)"
I
