I'm attempting to generalize my code through methods, however since I'm a newly introduced programmer, I need help.
Here is my code I'm trying to generalize:
I'm trying to generalize the code by putting it into this method:
What values would I have to put within the ( ) of this new keyPlacement method in order for this to work?
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 | /** * A piano that can be played with the computer keyboard. * * * @version: 0.1 */ public class Piano extends World { /** * Make the piano. */ public Piano() { super ( 800 , 340 , 1 ); Key key1 = new Key( "C" , "2c.wav" ); addObject(key1, 50 , getHeight()/ 2 ); Key key2 = new Key( "D" , "2d.wav" ); addObject(key2, 115 , getHeight()/ 2 ); Key key3 = new Key( "A" , "2d.wav" ); addObject(key3, 180 , getHeight()/ 2 ); Key key4 = new Key( "B" , "2b.wav" ); addObject(key4, 245 , getHeight()/ 2 ); } |
1 2 3 4 5 6 7 8 | public void keyPlacement() { } } |