Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

array being overwritten

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
We begin by testing your absorbancy by exposing you to this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic