• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking Elements of two arrayLists

 
John Vent
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am really struggling to get this to work,
My problem:

I have a class that holds details of items. These items are then added into another class as an arrayList.
I have a 3rd class that acts as a cash register that scans barcodes. I want these barcodes to match the arrayList barcode then get the details such as description and barcode etc and relay this to the till.

I however cannot figure this out, any guidance appreciated
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you not incorporate the barcode and item details into the same class. Having two Lists in parallel is a recipe for errors if they get out of step with each other.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a simple way to do this would be to create a barcode class with fields that hold a description and product name etc... Then you could have barcode be a field of whatever item or product class you have created.

It'd be easier to help if you posted some of your code.

Hunter
 
John Vent
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Why do you not incorporate the barcode and item details into the same class. Having two Lists in parallel is a recipe for errors if they get out of step with each other.


Sorry maybe I haven't explained clearly enough what the problem is (not even sure if it is possible)

My item class holds all of these details for an item and calculates prices etc.
The inventory class then adds these to an array (to create an inventory array of items)

For my till class I want a scanned barcode (at the till) to match details stored for it in the inventory and then relay these details (but only some of them) to the till.

I can't post any code unfortunately as I could get disciplined.

Feel like my head is repeatedly hitting a wall on this one.
 
John Vent
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hunter McMillen wrote:a simple way to do this would be to create a barcode class with fields that hold a description and product name etc... Then you could have barcode be a field of whatever item or product class you have created.

It'd be easier to help if you posted some of your code.

Hunter


Hmm that could be an option, I would have to rewrite my program a lot though.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if you're dead set on using the barcode the Barcode class would only really need a reference to an "item" then when the register "scans" the barcode it could retrieve the item's information, but then you'd have the same information in two places in your program which doesnt make much sense.
 
John Vent
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hunter McMillen wrote:Well if you're dead set on using the barcode the Barcode class would only really need a reference to an "item" then when the register "scans" the barcode it could retrieve the item's information, but then you'd have the same information in two places in your program which doesnt make much sense.


Is there not just a simple way for my till class to read a barcode and then check if it is in the List, if so to get the details of that object from my inventory class?

By definition a till cannot discern any information from a barcode, it must look it up in the inventory and get the relevant details, at the same time reducing that items quantity by 1.

Sorry if what I am saying does not make sence, I have no idea how else to explain this and i'm pretty new.

Thanks again
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try giving the item's and barcode's a common identifier, then you could look up the item by that identifier.

Hunter
 
John Vent
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hunter McMillen wrote:You could try giving the item's and barcode's a common identifier, then you could look up the item by that identifier.

Hunter

How would I go about doing that?
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


something like that I'd imagine.
Hunter.
 
John Vent
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hunter McMillen wrote:

something like that I'd imagine.
Hunter.


Thanks I will look into this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic