Nesting arbitrary objects in Java
Posted
by
user1502381
on Stack Overflow
See other posts from Stack Overflow
or by user1502381
Published on 2012-07-05T15:07:12Z
Indexed on
2012/07/05
15:15 UTC
Read the original article
Hit count: 223
java
I am having trouble solving a particular problem in Java (which I did not find by search). I do not know how to create a nested lists of objects - with a different type of object/primitive type at the end. For example:
*Note: only an example. I am actually doing this below with something other than Employee, but it serves as simple example.
I have an array of an object Employee. It contains information on the Employee.
public class Employee {
int age
int salary
int yearsWorking
public Employee () {
// constructor...
}
// Accessors
}
What I need to do is organize the Employees by quantiles/percentiles. I have done so by the following:
import org.apache.commons.math.stat.descriptive.rank.Percentile;
public class EmployeeSort {
public void main(String args[]) {
Percentile p = new Percentile();
Employee[] employeeArray = new Employee(100);
// filled employeeArray
double[] ageArray new double[100];
// filled ageArray with ages from employeeArray
int q = 25; // Percentile cutoff
for (int i = 1; i*q < 100; i++) {
// assign percentile cutoff to some array to contain the values
}
}
}
Now, the problem I have is that I need to organize the Employees first by the percentiles of age, then percentiles of yearsWorking, and finally by percentiles of salary. My Java knowledge is inadequate right now to solve this problem, but the project I was handed was in Java. I am primarily a python guy, so this problem would have been a lot easier in that language. No such luck.
© Stack Overflow or respective owner