This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm trying to code using java the following requirements.
The user must first enter a some requirements of an item (item code, item description, item weight and item price). Then upon entering the code once again the application should print the item description, the item weight and the item price.
I've managed to make the user input all the items and make the system print the requirements upon entering the code for the second time. However only the last product entered can be retrived from the system. If the user enters the 3 items and he needs to retrieve the first, the system prints and error message.
The problem lies in the fact that my array Lists are being overwritten each time the user is entering new data. Its as if the array list contains only one element all through the execution of the program. How can I get pas this problem. Any help please
It looks like you hacked an ItemDetails class, which was designed to hold the details for one data item, to "hold" multiple items, but changing it to keep a history of the values called by the setters.
Instead of doing that (having a single ItemDetails object with many arraylists of the fields), would it not be better to keep the ItemDetails class as is, and have multiple items by having an ArrayList of ItemDetails objects?