File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Totally lost on how to add objects into a array via userInput

 
Sam Acropolis
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Thanks,


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 :





 
K. Tsang
Bartender
Pie
Posts: 3223
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic