File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array being overwritten

 
Daniel Hyslop
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program with three classes the first `Employee class` introduces a hashIndex calculated from empName the second `EmployeeSort` takes the hashIndex and places the employee class instance into an array of which will be eventually be Employee class objects.I have the Last class passing the name and job using the JOptionPane unfortunately each pass overwrites the last entry in EmployeeSort .Could anyone point me to what I am doing wrong in the program.Heres the code
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoa!!! my eyes are cross-eyed after reading that code. What are you trying to do? I don't understand what you are trying to do here, but I think problem might be in this code



You are creating a new EmployeeSort in each iteration of the loops. Every time the loop finishes one iteration the empSort1 object goes out of scope \, and a new one is created whenver you do "new EmployeeSort". In each iteration EmployeeSort has only one employee's information. So, when the loop finishes the last EmployeeSort will have the last employees information. Is that your problem?
 
Daniel Hyslop
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
correct ,the aim of the program is to end up with an array of Employee objects in employeeSort ,sorted according to hashIndex == element
if the element == full then hashIndex +1.the final outcome requires an output from the mainProgram
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you need to have just one EmployeeSort object created outside the loop. Inside the loop you need to get the Employee objects to the one and only EmployeeSort object.

I'm not entirely sure what your setArray function does, but my guess is that it is suppossed to sort the employees. I think you need to clean up the code around there too. It is rather convuluted. It looks like you are trying to store the empolyee at the hashIndex, and in case of collision you move to the next index. There are much cleaner ways of doing that
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic