This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.