Totally lost on how to add objects into a array via userInput
Joined: Sep 30, 2012
Guys Im out of ideas on this one and decided to turn to the community. I working on a program that models a PC shop where the user picks the parts he wants for a laptop or desktop and as he picks i add up the total and display the results at the end of the program. I can prompt the users with a greeting and have the program run through selecting the RAM, HDD, and CPU but at line 119 the magic stops and no matter if I type "Y" or "N" the program is stuck at that particular loop.
No idea now how to have the objects selected with their made up prices get totaled and then sent to displayResults
Here is what I have so far:
this is my main super class, and i also have subclasses "ComputerList"(so I can add objects in the array) , "Desktop" and "Laptop"
This my ComputerList class which Im having the issues and am at a dead end :
Base on what you have already, there can be lots of improvement to make it better mainly in organizing the code (eg OO).
Why would work with an "array" when there are list and map collections? Your ComputerList class primary purpose is to store those 5 components. If I were you, using a map seems to be better. This way you can identify what each item and their corresponding values. With arrays, you must stick to the order you add them which can become messy. In fact, your ComputerList class as separate entity is really pointless I think. You can just define a list or map or array inside the Computer class and add to it when you know the item/value. Again order of adding items is key for list and array.
As for method DriveOption() in class Computer, you have userInput.next() twice. You can remove the first one, keep the one inside the do-while loop. Not sure if this will solve your loop problem.