GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Complicated Array Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Complicated Array Problem" Watch "Complicated Array Problem" New topic
Author

Complicated Array Problem

Alice Bickerstaff
Greenhorn

Joined: Dec 08, 2004
Posts: 2
Hi,

I have created a class ShoppingCart that constructs a new arry from a class called Item. The Item array consists of 10 elements. Each Item element holds an Item object that contains the instance variables



When the array is first created the first index of the array becomes non-null and the remaining nine indices are still null objects. As a new Item object is added to the Item array I need to compare the new objects barcode data with the existing array elements' barcode data. If the data are the same then I need to only update the quantity of the item and not store this object information again in a separate array. Only the quantity data needs to be updated.

Here is the code that I have so far for this particular algorithm. Although it doesn't create compile-time or run-time errors, it does not function as it should





Thanks for any help that is offered
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Just a thought - it might be easier if you changed your array to a Hashtable,
using the barcode as the key, then simply check containsKey()
Alice Bickerstaff
Greenhorn

Joined: Dec 08, 2004
Posts: 2
Thanks Michael,

I'll give that a try. Any ideas on how to make that happen using an array?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
 
GeeCON Prague 2014
 
subject: Complicated Array Problem