• Post Reply Bookmark Topic Watch Topic
  • New Topic

Full Array not showing  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't I get my notes F and G to show up in my results after I compile the file? I get all of my instruments to show up, but not all seven notes.


 
Heather Carey
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and I just noticed that my results are coming out the same, not random. i.e. fiddle A banjo B every time. Trying to go through the book and figure that one out.
 
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really ought to explain the details. What you mean is that you always get A for fiddle and B for banjo. They are however in haphazard order. You are choosing notes[music[i] / 7] and instruments[music[i] / 7], so you would expect to get the pairs matched.
 
Heather Carey
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi... Details...I'm trying to create a JAVA program that will display musical notes played by certain instruments. I have to check if the instruments are in tune and if they are playing (I haven't written this part yet).

I changed String instrument = instruments[music[i] / 7]; to String instrument = instruments[music[i] % 7]; so it would not pair.

At any rate, this problem has out of bound array exceptions I have to figure out.

Maybe a better way to display this is by each instrument and then within each instrument display the randomized notes if it is tuned and is playing.

I'll keep playing with it. Talking it through sometimes helps me.
 
Campbell Ritchie
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven’t told me anything I didn’t know already. What I meant was the type of error you were suffering; when I executed your program, I got a completely different output from what you said you had. You ought not to be trying to mess around with two errors simultaneously. Forget about the linking of instrument to note, and get the out of bounds exception sorted. Then go back to Banjo=F and Fiddle=A.

As for changing the / to %: where? why? It looks as if you were you simply guessing what to do. You can’t guess; that way leads disaster. Have you written down what you are doing? You want a pencil and a sheet of paper, and a large eraser (the latter is the most important ), so you can write down the contents of your arrays and see what would happen on a trial run. Another thing you should do is to print out the values of i / 7 and i % 7 etc., for each of the lines, so you can see what is happening as you execute your code. You should also remove the literal 7 and change it to music.length. That way, if you decimalise music, your arrays will still work.

So, where you you suffering that exception?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!