"Il y a peu de choses qui me soient impossibles..."
http://plainoldjavaobject.blogspot.in
jihwan kim wrote:
Now that I have bubble sorted my "diameters" array what would be the best way to sort my "planets" and "lengths" array to keep it straight when I sort the"diameters" array?
I am sure that is not what anybody meant.jihwan kim wrote:Wow thanks for reminding me that I am stupid.
As you have been told, parallel arrays are poor design; you should query that instruction with whoever told you about parallel arrays.I was suppose to create parallel arrays, . . .
That would make things worse; the main method is intended for starting the application, and nothing else. You are liable to create a large, un‑maintainable, class, which is another form of bad design.EDIT: Just wondering is there a way to create parallel arrays in just my Main instead of creating a separate class?
Not lazy; parallel arrays require much more work than a proper object‑oriented solution. You have to follow all your parallel arrays; if you sort array1, you have to duplicate all changes exactly in array2, array3, etc. That is error‑prone, and there is a risk of your missing out a change somewhere. Sorting a Planet[] array means you sort one array, and all the data for each Planet object stay together in that object.
And why are some people (internets) saying that creating parallel arrays isnt a good idea? Are they just lazy or is it a bad coding technique/etiquette? . . .
Not lazy; parallel arrays require much more work than a proper object‑oriented solution. You have to follow all your parallel arrays; if you sort array1, you have to duplicate all changes exactly in array2, array3, etc. That is error‑prone, and there is a risk of your missing out a change somewhere. Sorting a Planet[] array means you sort one array, and all the data for each Planet object stay together in that object.
Yes, but what difference would that make?jihwan kim wrote: . . . Can you not typecast values stored in arrays?
You mean use the same i throughout? You see what confusion is arising?I thought sorting and tracking would be easy seeing that i could make the index of my int variable equal the index of the double variable (a[j] = b[j]).
Or tying yourself in knots because you are stuck with a poor design?
Then I thought about declaring 4 more variables in my bubbleSort (i,j,k,l,m,n) . . .
jihwan kim wrote: all, but he makes us follow an unspoken rubric (i.e what the instructions says) so that we show him that we know how to do exactly what he asks us to do. I am not complaining by any means, I just have to follow instructions
![]()
Unless I am interpreting this the wrong way the instruction says:
Read the data into three parallel arrays
*planets(String) * = bullet points
*diameters(int)
*lengths(double)
Campbell Ritchie wrote:
I am sure that is not what anybody meant.jihwan kim wrote:Wow thanks for reminding me that I am stupid.
Campbell Ritchie wrote:
Not lazy;jihwan kim wrote:
And why are some people (internets) saying that creating parallel arrays isnt a good idea? Are they just lazy or is it a bad coding technique/etiquette? . . .
Or tying yourself in knots because you are stuck with a poor design?
It may be that he's doing it this way on purpose--showing you the icky approach first so that you'll appreciate the more OO approach when he has you do it again that way. If so, then I would call that acceptable. If he's actually teaching this as the right way to store and manipulate data though, then I'd take anything he teaches with a grain of salt.
It can be done using parallel arrays. When you're sorting, you have to make sure that every change you make to one array gets made to all of them. So if you swap planets[2] with planets[3], then you also have to swap diameters[2] with diameters[3] and lengths[2] with lengths[3].
jihwan kim wrote:I get that I have to swap the variables when I am making a change from the index, however I am completely stuck at how to code it right.
Whats messing me up is that because my bubbleSortArray has int[] a as the variable for the diameter index I dont know if I should add more parameters (String[]b or String[]a or double[] a) and make it equal (int[] a = double[] b) to each other when I know that this way is not allowed.*
Wouldnt having the same index parameter 'a' be the right way to go about it because the I am basing everything on the diameters index to keep track of the other 2 variables?
Edit: just wondering would it be easier to create another method so that when I printArray the switched diameter values, this new method would take the Index of the switched diameter and makes it equal to the corresponding planets and lengths index? #derp
regards
No idea what you're saying here.
Again, not sure what you're saying here
-Jeff
jihwan kim wrote:Having gone through the seven circles of hell, I honestly dont think that parallel arrays are that bad. I mean yeah it took my stupid brain a long time to figure out 6 lines of code, but in all seriousness that wasnt too bad.
If i had created a class as You and Campbell have suggested, I think that would've been much more work and unnecessary for this specific code.
Thank You - jeff, Campbell, Lalit, and Stevens.
Don't get me started about those stupid light bulbs. |