![]() Test by placing a second cat into the world before clocking Act. If it is not alone, make it shout "Hooray". Write code in the act method to do the following: If your cat is alone, let it sleep. (For testing, make the cat tired by calling some methods interactively. Change the act method of your cat to the following: If the cat is tired, it sleeps a bit, and then it shouts hooray. Change the act method of your cat so that it eats if it is hungy.ġ7. Change the act method of your cat so that it dances if it is bored. If it is not tired, it doesn't do anything.ġ5. Change the act method of your cat so that, when you click Act, if the cat is tired, it sleeps a bit. Make the cat do a routine of your choice, consisting of a number of the available actions in sequence.ġ4. When done, click the Act button in the execution controls.)ġ3. (Don't do this interactively - write code in the act method to do this. Test by pressing the Act button in the execution controls.ġ1. (That is: In the act method, write a call to the eat method.) Compile. (This is where you will write the code for all the following exercises.) Make the cat eat when it acts. Is the cat bored? How can you make it not bored?ġ0. The interesting methods are all "Inherited from Cat".ĩ. ![]() Try calling some of your cat's methods interactively, by using the cat's popup menu. ![]() Writing method calls (with and without parameters)Ĩ. How many parameters does the "sleep" method have? How many of the Cat's methods return a value?ħ. How many methods does the class Cat have?Ħ. Make sure that the editor is in Documentation view. Download the scenario here and open it in Greenfoot before continuing.ĥ. Write another method call for the "addAmount" method from exercise 1.Īll the following exercises are intended to be implemented in the Greenfoot scenario "fatcat". On paper, write a method call (note: this is a method call, not a signature) for the "play" method from exercise 1. The method has a parameter of type "int" that is called "number", and it returns a value of type "int".Ĥ. Write a method signature for a method named "process". The method has no parameters, and it does not return a value.ģ. Write a method signature for a method named "go". How many parameters does the method haveĢ.Does the method return a value? If yes, what is the type of the return value?.Look at the following method signatures: public void play() public void addAmount(int amount) public boolean hasWings() public void compare(int x, int y, int z) public boolean isGreater (int number) įor each of these signatures, answer the fllowing questions: It's just the application and the zip file.1. Do you know how to change the shm on a Mac? I can't find an installation folder on here. I don't see anything weird with it but I'm not sure. Comp Science Intro Greenfoot CH 2 Exercises are from the Introduciton to Proramming with Greenfoot book by Michael Kolling, second edition, Pearson Higher Ed (Additional Practice adapted from Andrew Kuemmel ’s GreenRoom worksheets) Additional Practice Chapter 2 Greenfoot 1. GifImage flipped = new GifImage("flipnyan.gif") Īctor actor = getOneObjectAtOffset(0, 0, clss) GifImage gifImage = new GifImage("nyan.gif") Greenfoot fatcat This is a game my teacher gave me and in my version I called the following methods from the super class cat. ShowText("Oh no! You ran out of time! :( Try again.", 300, 200) ShowText("Oh no! You ate the broccoli! Bleh! Try again.", 300, 200) Open the scenario in Greenfoot before continuing. Write a method signature for a method named 'process'. The method has no parameters, and it does not return a value. ShowText("You won! You finished in "+finalscore+" seconds!", 300, 200) Write a method signature for a method named 'go'. String finalscore= seconds.format(score) List broccoli= getObjects(Broccoli.class) List cupcakes = getObjects(Cupcake.class) You will be modifying the little-crab scenario, and recording your observations. ![]() Student Name: Date: Score: Instructions Answer the following questions as you work through the exercises in Chapter 2 of the text book. GreenfootSound backgroundMusic = new GreenfootSound("nyanmusic.mp3") ĪddObject(new Cupcake(), Greenfoot.getRandomNumber(580)+10,Greenfoot.getRandomNumber(380)+10) ĪddObject(new Broccoli(), Greenfoot.getRandomNumber(580)+10, Greenfoot.getRandomNumber(380)+10) Introduction to Programming with Greenfoot. DecimalFormat seconds = new DecimalFormat("#.00")
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |