The directions are in the comment section of the code public class Emoticon exte
ID: 3553791 • Letter: T
Question
The directions are in the comment section of the code
public class Emoticon extends Actor { /** *INSERT CODE BELOW * Create two instance varaibles of type String * one named sound * one named image */ /** * 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. * */ /** * Act - do whatever the Emoticon wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ 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 * */ } } }
Explanation / Answer
public class Emotion extends Actor {
private String sound;
private String image;
public Emotion(String newImage, String newSound) {
sound = newSound; //setting field sound;
image = newImage; //setting field image
setImage(newImage); //calling method setImage to set image
}
public void act() {
if(Greenfoor.mouseClicked(this)) {
Greenfoot.playSound(sound); //playing the sound;
}
}
}