• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Complicated Array Problem

 
Alice Bickerstaff
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael,

I'll give that a try. Any ideas on how to make that happen using an array?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic