• 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

Sending ArrayList from one class to another, not passed as parameter

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a few classes.
Shift : Each shift contains a list of 6-12 employees
Employee : Just an object
Payroll : Creates 14 shifts

I need to pass the list from Shift to Payroll so I can add each Employee to a HashSet but I am a bit lost, as my methods don't seem to work. If someone could point me in the right direction or shoot some code my way it would be much appreciated.





 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is it that isn't working as you expect? It's a bit much to plow through 200 lines of code to attempt to answer a vague question; something more specific would help us give you an answer to the question you really mean to ask.

rc
 
Jason Job
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I was posting this, I was thinking to myself that I should have been more specific and sure enough! heh

I need the ArrayList shiftWorkers in class Shift to be sent out so that I could use it to create a new ArrayList in PayRoll. Currently I have a method that just returns the ArrayList shiftWorkers and then in payroll on line 50 I have a method that takes it and adds each entry into a new arraylist. It returned null and thus I commented it out.
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Do you still have a question?
rc
 
Jason Job
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. In what way would you take an ArrayList<Employee> shiftEmployees in shift, and return it so you could then add it to ArrayList<Employee> acceptedFromReturns in PayRoll. I am unsure how I would go about creating methods like this. Like I said, it didn't work and it output null.
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your statement "it didn't work" doesn't tell me WHAT didn't work. If it "returned null", then supposedly there is a line of code you are talking about that you expected to return something and did not. I suppose I might be able to figure it out at this point, but experience tells me I have a good chance of guessing the wrong thing.

In general, I would expect some part of your code to have logic that is run when it is time to run payroll, let's call this code "Payday"; it isn't necessarily a class itself, although all code in Java is in some class.

I would expect that when the Payday code is run, it invokes a method that gives it one or more Shift objects for which it is going to generate a PayRoll for them. The way information gets from one object to another is through methods; either parameters are passed in the methods (usually for sending information into the other class) or objects or values are returned from methods (for getting them back).

Is that any help?

rc
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic