So I have 3 Parallel Arrays. I need a method that will allow for the user to add to these arrays. As well as another method to be able to identify a certain item and remove it. As well as another method to identify an item and edit/change the contents of that item in the array.
These are my 3 arrays...
I need to add the brand name of the computer to: String[] computerBrand
I need to add the processor speeds to: double[] computerSpeed
and I need to add the computers price to: double[] computerPrice
The first array (string) holds the brand name of computer. (Dell) the second array (double) holds the processor speed of the computer. (2.5) the third array (double) holds the price of the computer. (1500)
How do I take user input and put them in the array?
(I CANNOT USE ARRAYLISTS)
For taking input look at the Scanner class.
Scanner
For adding the values to your arrays just do this:
computerBrand[i] = <value_brand>;
computerSpeed[i] = <value_speed>;
computerPrice[i] = <value_price>;
i++;
where these 3 values are the one read by the Scanner,
and
i
is some index/counter integer variable.But first make sure you initialize your arrays e.g.:
By reading the code you can understand a simple thing: every array will share the same index.
For your real code, you just need to get name, price and speed of the pc and put everything in the arrays using the same index. If you use it in separate code you can store the last index and use it (more info depends on how it should work.).