• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Complicated Array Problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
reply
    Bookmark Topic Watch Topic
  • New Topic