in the following code i am not able to inherit into the subclass MyCat, the value of the variable 'distance' from the superclass Cat
Cat superclass:
/**
* Walk a bit to the left. 'distance' determines how far to walk. Use small numbers (1 to 10).
*/
public int walkLeft(int distance)
{
walk(distance, -10, "cat-walk.png", "cat-walk-2.png");
return distance;
}
/**
* Walk a bit to the right. 'distance' determines how far to walk. Use small numbers (1 to 10).
*/
public int walkRight(int distance)
{
walk(distance, 10, "cat-walk-right.png", "cat-walk-right-2.png");
return distance;
}
/**
* Internal walk method. Walk a given distance into a given direction, using given images.
*/
public void walk(int distance, int direction, String img1, String img2)
{
for (int i=0; i<distance; i++)
{
setImage(img1);
wait(4);
setLocation(getX() + direction, getY());
setImage(img2);
wait(4);
setLocation(getX() + direction, getY());
}
setImage("cat.png");
}
MyCat subclass:
public class MyCat extends Cat
{
public boolean tired = false;
public boolean hungry = false;
public boolean bored = true;
private boolean isAlone = true;
public int numberOfCats = 0;
/**
* Act - do whatever the MyCat wants to do.
*/
public void act()
{
walkLeft(int distance);
walkRight(int distance);
// Repeared activity
walkRight(int distance);
//
alone();
if(isAlone != true)
{
shoutHooray();
dance();
eat();
//Repeated Activity
shoutHooray();
//
walkLeft(int distance);
walkRight(int distance);
tired = true;
getObjectsInRange(10, MyCat.class);
removeTouching(MyCat.class);
isAlone = true;
}
}
