In the first class you need to: Add two instance variables that are of type Stri
ID: 3553684 • Letter: I
Question
In the first class you need to:
Add two instance variables that are of type String[]
One will be an array of images and the other will be an array of sounds. You are not suppose to include the file suffix in this portion of the code.
In the next class you need to:
Write a "for" loop
Needs to loop 5 times and should use the method addObject (i.e. Actor object, int x, int y) to add new images to the program. Will need to concatinate the ".png" for images and ".wav" for the sounds (I know you do not have these, but just use something generic and I will modify). You need to determine the x value using a mathematical calculation. The y value can be either hard coded or calculated.
I know this is not very specific, but I am hoping someone can write some general code, including for the image andsound files, and that I can modify it as required.
Explanation / Answer
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; import java.lang.Object; /** * Write a description of class HomeworkWorld here. * * @author (your name) * @version (a version number or a date) */ public class HomeworkWorld extends World { /** * INSERT CODE BEOLW * Add two instance variables that are of type String * one will be an array of images * one will be an array of sounds * DO NOT INCLUDE THE FILE SUFFIX - add that through code later * * Note - each image is 55x55 */ private String smileImages = { "smiley1", "smiley2", "smiley3", "smiley4", "smiley5" }; private String smileSounds = { "crying", "happy", "hello", "ohno", "raspberry" }; /** * Constructor for objects of class HomeworkWorld. * */ public HomeworkWorld() { // Create a new world with 400x100 cells with a cell size of 1x1 pixels. super(400, 100, 1); makeImages(); } /** * INSERT CODE BELOW * Write a "for" loop * It should loop 5 times (you can either hard code 5 or use code) * It should use the method addObject( Actor object, int x, int y) to add new Emoticons to your world. * Note: concatinate the ".png" for images and ".wav" for the sounds * * Determine the x value using a mathematical calculation * The y value can be either hard coded or calculated * */ private void makeImages() { // make the white keys for(int i = 0; i < smileImages.length; i++) { Image image = new Image(smileImages, smileSounds+".wav", "IMAGE.png", "IMAGE-down.png"); addObject(image, 54 + (i*63), 140); } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.