This content has been marked as final. Show 4 replies
So you have an array of... what?
If price is an array of double, you don't need any special method to obtain the value at a particular index.
Is this all in one class? It sounds as if you already know how to get the price for the 5th cd, simply use price (since arrays start at 0 not 1).
A warning though: You're using what's called the "parallel array anti-pattern" where all your pertinent information is stored in several arrays that are called parallel since the 5th CD's title is at title, it's price is at price, and the artist is stored at location artist. The problem with this pattern is it is easy for one of the arrays to go out of synch messing up all the data. Better is to create a CD class that holds the title, artist and price information. Then you could have a single array of CD objects with all the pertinent information tied together as it should be. THEN you'd need and use a getPrice() method.
in your arrays:
title[x], title[y], price[z]
each element is addressed by the index and is self contained, I've not a clue what you are talking about doing in your post.
For instance to access the 3rd price:
Java starts at index 0 on arrays, so the 3rd element of the array is at index = 2.
double d = price;