You are on page 1of 2

The FatCat worksheet

Method signatures 1. Look at the following method signatures: public public public public public void play(); void addAmount(int amount); boolean hasWings(); void compare(int x, int y, int z); boolean isGreater (int number);

For each of these signatures, answer the following questions: a. What is the method name? b. Does the method return a value? f !es, what is the t!"e of the return value? c. #ow man! "arameters does the method have $. '. Write a method signature for a method named %go%. &he method has no "arameters, and it does not return a value. Write a method signature for a method named %"rocess%. &he method has a "arameter of t!"e %int% that is called %number%, and it returns a value of t!"e %int%. )n "a"er, write a method call *note: this is a method call, not a signature+ for the %"la!% method from e,ercise 1. Write another method call for the %add-mount% method from e,ercise 1.

(.

All the following exercises are intended to be implemented in the Greenfoot scenario "fatcat". Open the scenario in Greenfoot before continuing. Reading documentation .. )"en the editor for class Cat. /ake sure that the editor is in Documentation view. #ow man! methods does the class 0at have? #ow man! of the 0at2s methods return a value?

1.

3.

#ow man! "arameters does the %sleep% method have?

Writing method calls (with and without parameters) 4. &r! calling some of !our cat2s methods interactivel!, b! using the cat2s "o"u" menu. &he interesting methods are all % nherited from 0at%. s the cat bored? #ow can !ou make it not bored? )"en the editor for class MyCat. *&his is where !ou will write the code for all the following e,ercises.+ /ake the cat eat when it acts. *&hat is: n the act method, write a call to the eat method.+ 0om"ile. &est b! "ressing the -ct button in the e,ecution controls. 11. /ake the cat dance. *Don2t do this interactivel! 7 write code in the act method to do this. When done, click the -ct button in the e,ecution controls.+ /ake the cat slee". /ake the cat do a routine of !our choice, consisting of a number of the available actions in sequence.

5. 16.

1$. 1'.

If statements 1(. 0hange the act method of !our cat so that, when !ou click -ct, if the cat is tired, it slee"s a bit. f it is not tired, it doesn2t do an!thing. 0hange the act method of !our cat so that it dances if it is bored. *8ut onl! if it is bored.+ 0hange the act method of !our cat so that it eats if it is hungr!. 0hange the act method of !our cat to the following: f the cat is tired, it slee"s a bit, and then it shouts hoora!. f it is not tired, 9ust shouts hoora!. *For testing, make the cat tired b! calling some methods interactivel!. #ow can !ou make the cat tired?+ Write code in the act method to do the following: f !our cat is alone, let it slee". f it is not alone, make it shout %#oora!%. &est b! "lacing a second cat into the world before clicking -ct.

1.. 11. 13.

14.

You might also like