Require help with ArrayList
Hi I've started learning Java OOP a couple of weeks back and I've hit a huge wall which I'll explain in detail.
I've been asked to make a small market program which can do things like modify prices, add products, remove products, etc.
I've finished all my classes and so forth and I'm now at the point where a user would request information to access certain features on the system. The first function I wanted to add was being able to request a products(objects) bar-code number through a command line interface by simply entering it in.
I have methods like getBarcode() which would obviously do that but the problem is I have 0 knowledge on HOW I'm actually going to access the array and have it read each section of the array i.e. [0], [1], [2]... until it finally finds that bar code and displays that products information.
Finally I'll show you some code that I think we be useful.
ArrayList<Item> ItemList = new ArrayList<Item>();
ItemList.add(new Grocery(50, "APPLE", 1, 0.0, 2.50));
ItemList.add(new Grocery(50, "BANANA", 2, 0.0, 2.50));
ItemList.add(new Grocery(50, "COCONUT", 3, 0.0, 5.00));
ItemList.add(new Grocery(50, "MANGO", 4, 0.0, 3.75));
ItemList.add(new Grocery(50, "ORANGE", 5, 0.0, 2.50));
ItemList.add(new Houseware(25, "LARGE COUCH", 6, 0.0, 250, "COTTON"));
ItemList.add(new Houseware(25, "LARGE CHAIR", 7, 0.0, 275, "VELVET"));
ItemList.add(new Sweets(50, "SNICKERS", 8, 0.0, 1.00, "CHOCOLATE"));
ItemList.add(new Sweets(50, "MALTESERS", 9, 0.0, 1.00, "CHOCOLATE"));
ItemList.add(new Toys(75, "G.I. JOE", 10, 0.0, 10, "M"));
ItemList.add(new Toys(75, "BARBIE", 11, 0.0, 10, "F"));
If anyone could tell me how I can do this it would be incredibly helpful.