关于我的POJO实施
Class Employee {
Integer empId;
String empName;
List<Allowance> allowances;
List<Deduction> deductions;
//getter and setter
public Employee(Integer empId, String empName,
List<Allowance> allowances, List<Deduction> deductions) {
this.empId = empId;
this.empName = empName;
this.allowances = allowances;
this.deductions = deductions;
}
}
Class Allowance {
Integer allwId;
Employee emp;
String allwName; // Basic Pay, DA, HRA etc..
float amount;
//getter and setter
}
Class Deduction {
Integer dedId;
Employee emp;
String dedName; // FBS, Loan, Tax etc..
float amount;
//getter and setter
}
例如,我增加了2名员工。 列表allws1有基本工资,DA,HRA和deds1的金额为FBS,Tax的金额。 列表allws2有基本支付金额,DA和deds2有FBS,贷款,税金额。 并为每个员工分配两个类似的东西,
Employee emp1=new Employee(1,"Mickel", allws1, deds1);
Employee emp2=new Employee(2,"John", allws2, deds2);
List<Employee> employees = new ArrayList<Employee>();
employees.add(emp1); employees.add(emp2);
我可以像这样以枢轴方式表示员工名单,
| empName |基本工资| DA | HRA | FBS |贷款|税|
| Mickel | 1400 | 120 | 50 | 20 | 0 | 27 |
|约翰| 1200 | 120 | 0 | 20 | 105 | 23 |
答案 0 :(得分:0)
您已经在数据对象Allowance
和Deduction
中收集了数据。你需要的是一个不同的观点。因此,您可以将它们放入JTable
或以所需格式将其打印到控制台。
答案 1 :(得分:0)
如果我正确理解了您的问题,您希望以特定方式输出“员工”列表的元素。
为此,您可以Override
Employee
类中的方法toString()
。
此方法返回String
的{{1}}表示。
例如,
Object
之后,您可以实现另一个方法,该方法将输出带有标题的@Override
public String toString() {
String bp = ""; // get the BP
String da = ""; // get the DA
// etc...
return String.format("|%s|%s|%s|%s|%s|%s|%s|", this.empId, bp, da, ...); // this line won't compile
}
列表。