aspose file tools*
The moose likes Beginning Java and the fly likes Checking Elements of two arrayLists Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Checking Elements of two arrayLists" Watch "Checking Elements of two arrayLists" New topic
Author

Checking Elements of two arrayLists

John Vent
Greenhorn

Joined: May 17, 2011
Posts: 11
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

Joined: Oct 13, 2005
Posts: 36599
    
  16
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

Joined: Mar 13, 2009
Posts: 492

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


"If the facts don't fit the theory, get new facts" --Albert Einstein
John Vent
Greenhorn

Joined: May 17, 2011
Posts: 11
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

Joined: May 17, 2011
Posts: 11
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

Joined: Mar 13, 2009
Posts: 492

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

Joined: May 17, 2011
Posts: 11
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

Joined: Mar 13, 2009
Posts: 492

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

Joined: May 17, 2011
Posts: 11
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

Joined: Mar 13, 2009
Posts: 492



something like that I'd imagine.
Hunter.
John Vent
Greenhorn

Joined: May 17, 2011
Posts: 11
Hunter McMillen wrote:

something like that I'd imagine.
Hunter.


Thanks I will look into this
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking Elements of two arrayLists
 
Similar Threads
Need Help in barcode display
iReport & Barbecue
iReport & Barbecue
Bar Code Generation API from Sun
Barcode input