aspose file tools*
The moose likes Beginning Java and the fly likes ? in a Linked List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "? in a Linked List" Watch "? in a Linked List" New topic
Author

? in a Linked List

Shananne DuFrame
Ranch Hand

Joined: Nov 13, 2006
Posts: 51
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.

Thanks,
Shananne
Shananne DuFrame
Ranch Hand

Joined: Nov 13, 2006
Posts: 51
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

Sorry forgot to add that in the first post!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ? in a Linked List