I Want to build a logic for an Object of ArrayList.
Below i will provide Boilerplate for a program for which i want a logic to implement.
1. In the above program there are 2 domain class Employee, Result
2. In the main program inside TestProgram class i have added 8 Object of Employee inside empList ArrayList.
3. if you run the program the output will be as below
List Size : 8
Name: Tom Emp ID: 1
Name: Tom Emp ID: 2
Name: Tom Emp ID: 3
Name: Tom Emp ID: 4
Name: Tom Emp ID: 6
Name: Jerry Emp ID: 7
Name: Jerry Emp ID: 8
Name: John Emp ID: 9
4. The Output i require is in resList ArrayList is
Name: Tom, From ID: 1, To ID: 4, Count: 4
Name: Tom, From ID: 6, To ID: 6, Count: 1
Name: Jerry, From ID: 7, To ID: 8, Count: 1
Name: John, From ID: 9, To ID: 9, Count: 1
5. The logic to generate the output is
If Name is same & Emp ID is in sequence then update the To ID, if sequence is break then create a separate entry in resList.
Please explain waht you are trying to do, so we can help you do it.
Don't use underscores in variable names. Not emp_name but empName. Actually, if you are inside an Emplyee class, you shoulsn't use emp at all; simply write name. What does emp_add mean? Why is it a String? There is no such thing as an add in real life, so there shoudn't be a field called add.
Why are you using all those setXXX methods? Why are you not initialising those fields in the constructor?
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop