• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Java reading from files error - Separate chaining

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For my program I have to read lines from a directory folder containing multiple text documents and each line in the text document has a name and a number. My program is supposed to read the line and assign the string variable key the name and the double variable value the number. Then create a hashcode using a hashcode function and then storing the data in a bucket array of linkedlists where the collisions are handled by seperate chaining.
The file contains text documents with the following data inside them: http://pastebin.com/6mAvpE6X. After running multiple tests my program works fine when there aren't any duplicate names but when the first duplicate name comes up it doesn't do anything so I thought maybe my program is stuck in a while loop in the addEntry class but I can't figure out how to fix it. What is supposed to happen is that if the program detects a duplicate name within the Linked list of a certain index its supposed to add the new value to the sum variable of the node with the same name that is already present in the linked list. It processes the first file fine but gets stuck at second text file and runs forever. Any help is appreciated. I tried to debug the code but at no success. The compilation of the program goes fine too. Thank You for your help

 
Master Rancher
Posts: 4663
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any debugging println() in there.

It should be possible to produce a seriously cut down version and run it with suitable debugging to trace exactly where it is going, and what values it is using.

Once you have a run of that, with all the debug output, you'll be in a better place to trace what's going on.
 
Bartender
Posts: 7297
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see a problem with this

This is the only place that avg is calculated. This is at the point of initialization and at this time sum is zero and count is zero. Although your setSum() adds to sum and count those are never reapplied to compute a new avg. Seems like your getAvg() would always want to perform the calculation on the fly.

Can you post (cut and paste) some small samples of files that you are testing with?
 
Carey Brown
Bartender
Posts: 7297
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

    Bookmark Topic Watch Topic
  • New Topic