1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Emoticon here. * * @author (your name) * @version (a version number or a date) */ public class Emoticon extends Actor { /** *INSERT CODE BELOW * Create two instance varaibles of type String * one named sound * one named image */ private String sound; private String image; private String[] images ={ "smiley1" , "smiley2" , "smiley3" , "smiley4" , "smiley5" }; private String[] sounds = { "hello" , "happy" , "crying" , "ohno" , "raspberry" }; /** * INSERT CODE BELOW * Write a construtor method * The method should have two parameters * type: String name: newImage * type: String name: newSound * * The method should * 1. set the instance variable image to the value passed by the corresponding parameter * 2. set the instance variable sound to the value passed by the corresponding parameter * * 3. Use the method setImage( java.lang.String filename ) to set the image. * */ public Emoticon(String newImage, String newSound) { image=newImage; sound=newSound; setImage(image); } /** * play a sound when the mouse is clicked in the emotion image */ public void act() { // When the mouse is click on this object, play the sound. if (Greenfoot.mouseClicked( this )) { /** * INSERT CODE BELOW * Use the method Greenfoot.playSound( java.lang.String filename ) to play the sound * */ Greenfoot.playSound(sound); } } } |

