aspose file tools*
The moose likes Beginning Java and the fly likes Sending ArrayList from one class to another, not passed as parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sending ArrayList from one class to another, not passed as parameter" Watch "Sending ArrayList from one class to another, not passed as parameter" New topic
Author

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

Jason Job
Greenhorn

Joined: Sep 26, 2011
Posts: 17
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.





Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
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

Joined: Sep 26, 2011
Posts: 17
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

Joined: May 29, 2005
Posts: 479
Ok. Do you still have a question?
rc
Jason Job
Greenhorn

Joined: Sep 26, 2011
Posts: 17
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

Joined: May 29, 2005
Posts: 479
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
 
Consider Paul's rocket mass heater.
 
subject: Sending ArrayList from one class to another, not passed as parameter