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.
Hello, I've been working on an assignment That contains 4 classes.
Grocery - contains date for item and aisle GList - contains node based list and other info InvalidAisleException - for invalid aisles TestList - implements the others
The program reads data in from a file in the format as such: 4 milk 4 bread 6 eggs 1 cheese 3
This is how the output should be after running the program: InvalidAisleException: Aisle must be 1-5: bread shows aisle 6 The file c:\\TestFile2.txt contains the following items: milk in aisle 4 eggs in aisle 1 cheese in aisle 3
I think I know where my problem may be but am unsure of what may be causing it. Would appreciate any ideas.
Here's my code where I think the problem may be: (This is in my TestList class)
If seeing more code would help better figure it out let me know. I've tried moving things around and using the loops differently and it just seems to get worse. If I move the list.printList out of the for loop it only prints one item such as: milk in aisle 4. Is the way I've coded it not really storing the information in the nodes? When I check list length it does say 4. But why will the list.print() not work outside the loop?
Here is my print method from the GList class:
And this is my toString Method from the Grocery class which obviously what is printing the list, because it displays 'item in aisle *' as coded.
I've tried multiple things with no luck. A lead in the right direction would be helpful.
Joined: Nov 13, 2006
Oh this is the actual output I am getting:
Enter the input file name: c:\\TestFile2.txt
The file c:\\TestFile2.txt contains the following items: milk in aisle 4 InvalidAisleException: Aisle must be 1-5: bread shows aisle 6 bread in aisle 6 eggs in aisle 1 cheese in aisle 3