im at the end of chapter 5 in the book and im stuck at creating the black piano keys. the given scenario uses for loops which arent introduced untill chapter 6. here is the code for the world class Piano. in the code Key is the actor class and key is a variable in the class Key. im supposed make black keys but they arent supposed to be next to each other like in a normal piano. this codes puts them next to each other like the white keys. i tried putting in an if statement. the class compiles but the greenfoot window just goes white. the if statement i used is
if (! blackKeys.equals("") ).
this statement is put in the while loop for the black keys. can you tell me whats going wrong?
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * A piano that can be played with the computer keyboard. * * @author: M. Kolling * @version: 0.4 */ public class Piano extends World { private String[] whiteKeys = { "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\\" }; private String[] whiteNotes = { "3c", "3d", "3e", "3f", "3g", "3a", "3b", "4c", "4d", "4e", "4f", "4g" }; private String[] blackKeys = { "q", "w", "", "t", "u", "", "o", "p", "", "]"}; private String[] blackNotes = { "3c#", "3d#", "", "3f#", "3g#", "3a#", "", "4c#", "4d#", "", "4f#"}; /** * Make the piano. This means mostly, apart from defining the size, * making the keys and placing them into the world. */ public Piano() { super(800, 340, 1); makeKeys(); } /** * Create the piano keys and place them in the world. */ private void makeKeys() { int i = 0; while (i < whiteKeys.length) { Key key = new Key(whiteKeys[i], whiteNotes[i] + ".wav" , "white-key.png", "white-key-down.png"); addObject(key, 54 + (i*63), 140); i = i + 1; } int a = 0; while (a< blackKeys.length ) { Key key = new Key(blackKeys[a], blackNotes[a] + ".wav", "black-key.png", "black-key-down.png"); addObject (key, 85 + (a*63), 86); a = a +1; } } }