• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

? in a Linked List

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic