Start Here

Media Resources

File Conversion

For most of the following exercises, you will need the Greenfoot scenario "fatcat". Download the scenario here and open it in Greenfoot before continuing.

Method Signatures

Fill out this form with a pair programming partner. We will discuss answers together as a group.

Writing method calls (with and without parameters)

Try calling some of your cat's methods interactively, by using the cat's popup menu. The interesting methods are all "Inherited from Cat".

Is the cat bored? How can you make it not bored? Try it.

Open the editor for class "MyCat". (This is where you will write the code for all the following exercises.) Make the cat eat when it acts. (That is: In the act method, write a call to the eat method.) Compile. Test by pressing the Act button in the execution controls.

Make the cat dance. (Don't do this interactively - write code in the act method to do this. When done, click the Act button in the execution controls.)

Make the cat sleep.

Make the cat do a routine of your choice, consisting of a number of the available actions in sequence.

If statements

Change the act method of your cat so that, when you click Act, if the cat is tired, it sleeps a bit. If it is not tired, it doesn't do anything.

Change the act method of your cat so that it dances if it is bored. (But only if it is bored.)

Change the act method of your cat so that it eats if it is hungry.

Change the act method of your cat to the following: If the cat is tired, it sleeps a bit, and then it shouts hooray. If it is not tired, just shouts hooray. (For testing, make the cat tired by calling some methods interactively. How can you make the cat tired?)

Write code in the act method to do the following: If your cat is alone, let it sleep. If it is not alone, make it shout "Hooray". Test by placing a second cat into the world before clocking Act.