This site requires JavaScript, please enable it in your browser!
Greenfoot back
Toodumbtocode
Toodumbtocode wrote ...

2018/10/26

Need help adding black keys for the piano project....

Toodumbtocode Toodumbtocode

2018/10/26

#
I'm very confused on how to add the black keys do I do the same for how I did the white keys??? They said that I need to make a new method for it but i dont know what to put. :( please help, thank you.
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
    private String [] names = {"q","w","e","r","t","y","u","i","o","p","[","]"};
    private String [] whiteNotes= {"3c","3d","3e","3f","3g","3a","3g","4c","4d","4e","4f","4g"};
     
    /**
     * Make the piano.
     */
    public Piano()
    {
        super(800,340,1);
        
        for(int k=0; k<names.length; k++){
            Key key = new Key(names[k] , whiteNotes[k] );
            addObject(key, 50+k*63,140);   
         
            }
   
         
      
        
 
 
 
    }
    public void makeKeys()
    {
         
    }
}
sup
Pretty cool
this thing
It is PRETTY cool
really cool
cool
ok its cool
bye
danpost danpost

2018/10/26

#
Toodumbtocode wrote...
I'm very confused on how to add the black keys do I do the same for how I did the white keys??? They said that I need to make a new method for it but i dont know what to put. :( please help, thank you. << Code Omitted >>
Refactoring what you currently have (starting at line 7 above), you have this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public Piano()
{
    super(800,340,1);
    makeWhiteKeys();
 
}
 
private void makeWhiteKeys()
{
    for (int k=0; k<names.length; k++)
    {
        Key key = new Key(names[k] , whiteNotes[k] );
        addObject(key, 50+k*63, 140);
    }
}
You can create another method, very similar to makeWhiteKeys, for making the black keys and call it from line 5.
Toodumbtocode Toodumbtocode

2018/10/30

#
Thank you so much!
You need to login to post a reply.