If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

For now my code only finds whether the item is available or not. But what i want to do is to print out the name of the item found along with its quantity and cost.
Please help me with this. I have been struggling with it for a long time

Re: I am a beginner in java....

Why is your ItemFound method creating several items. A method should do exactly what it's name suggests it should do, nothing more and nothing less. By all means have a method that initialises your data but call it something that says that's what it is doing.

Also why are you passing values into the constructor of each item and then immediately changing the values with setXXX, why not pass the correct values into the constructor to start with. And why are you calling getXXX on all your items and ignoring the returned values?

If you want to print out the details of the item then you need a method that takes the item name as a parameter and returns the item with that name. Once you have the item you can then use the getXXX methods to extract the details from it. Remember to handle the case where someone asks for an item you don't have. In such a case your method can either return null or possibly throw an exception, which will need handling in the calling code.