Rob Spoor wrote:A Thread ends when its run() method ends.
Ralph Cook wrote:It would help if you could point to a line of code or an output that shows your error. Otherwise, to help you, I first have to figure out what you mean by "when the loop is done" and where you're creating this object and what evidence you have that the amount is incorrect.
rc
fred rosenberger wrote:If you know your array needs to hold four items, I'd declare it as a member variable...
then your constructor would be something like
(note - i'm working on a loaner pc, which does not have the JDK installed, so I can't test/verify my example)
Obviously you'd need to adjust it to pass in the other params, but this might give you a few ideas.
fred rosenberger wrote:I'm not sure I can answer all your questions, but...
A "list of item numbers ordered (up to four)" to me sounds like you'd want an array of size four. you'll need methods to add or delete items, and to make sure you don't try and add a fifth.
Alternatively, you could just have four integers called something like "orderId1", "orderID2", etc. you could have specific methods for adding or deleting each of the four, plus a method for getting each. Using an array could be simpler, and make your life easier if next week you need to update it to have 8 orders (or 12, or 2000).
My PERSONAL opinion would be you should NOT have a variable holding the price of all items. If you have a list of the items, you should calculate the total when you need it. If you have a variable, you need to do a lot more updating each and every time an item is added or deleted, and you're data can become out of sync if that gets messed up.
Another tip would be to not store prices as floats. you are dooming your code to weird rounding issues. Money should be stored as an atomic unit, which (for the U.S.) is pennies. Then you can re-format it as needed when you want to print/display it.