其中(Contractor)表示该员工是合同工,其他人员为普通员工
对于普通员工,公司需缴纳20%的各类社会保险,对于合同工公司支付5%的社会保险要求输出格式如下:
公司:<公司名> ,<总薪水>,<社会保险费用总和>部门: <部门1>,<部门薪水>,<部门社会保险费用总和>
部门成员:<成员一>,<员工薪水>,<社会保险费用>
部门成员:<成员二>,<员工薪水>,<社会保险费用>
…部门: <部门2>,<部门薪水>,<部门社会保险费用总和>
部门成员:<成员一>,<员工薪水>,<社会保险费用>
部门成员:<成员二>,<员工薪水>,<社会保险费用>公司:MacroSoft,18500,1675公司:MacroSoft,18500,1675
部门:R&D,13000,1100
部门成员:Jason,3000,600
部门成员:Peter,6000,300
部门成员:James,4000,200
部门:HR,5500,575
部门成员:Carol,2000,400
部门成员:Daisy,3500,175输出以后是这样样子,公司、部门和员工名字和上面一样,员工中jason和carol是Contractor的员工(合同工)。public class SalaryStats { public static void main(String[] args) {
Company company = new Company("MacroSoft", 18500, 1675);
company.init();
company.export();
}
}public class Company {
private String companyName;
private int overallSalary;
private int overallInsurance;
private Deparatment[] departments; public Company(String companyName, int overallSalary, int overallInsurance) {
super();
this.companyName = companyName;
this.overallSalary = overallSalary;
this.overallInsurance = overallInsurance;
}
/**
 * 定义员工和部门状况
 */
public void init() {
Employee jason = new Employee("Jason", 3000, 600);
Employee peter = new Employee("Peter", 6000, 300);
Employee james = new Employee("James", 4000, 200);
Employee carol = new Employee("Carol", 2000, 400);
Employee daisy = new Employee("Daisy", 3500, 175);
Deparatment department1 = new Deparatment("R&D", new Employee[] { jason,
peter, james }, 13000, 1100);
Deparatment department2 = new Deparatment("HR", new Employee[] { carol,
daisy }, 5500, 575);
departments = new Deparatment[]{department1,department2};
}
/**
 * 输出公司状况
 */
public void export() {
System.out.println("公司:" + companyName + "," + overallSalary + ","
+ overallInsurance);
for (int i = 0; i < departments.length; i++) {
departments[i].export();
}
}}public class Deparatment {
private String name;
private Employee[] departmentMember;
private int overallSalary;
private int overallInsurance; public Deparatment(String name, Employee[] departmentMember,
int overallSalary, int overallInsurance) {
super();
this.name = name;
this.departmentMember = departmentMember;
this.overallSalary = overallSalary;
this.overallInsurance = overallInsurance;
}
/**
 * 输出部门状况
 */
public void export(){
System.out.println("部门:"+name+","+overallSalary+","+overallInsurance);
for (int i = 0; i < departmentMember.length; i++) {
departmentMember[i].export();
}
}}
public class Employee {
private String name;
private int salary;
private int insurance; public Employee(String name, int salary, int insurance) {
super();
this.name = name;
this.salary = salary;
this.insurance = insurance;
} /**
 * 
 * @return 返回名字
 */
public String getName() {
return name;
} /**
 * 
 * @param 设置名字
 */
public void setName(String name) {
this.name = name;
} /**
 * 
 * @return 返回工资
 */
public int getSalary() {
return salary;
} /**
 * 
 * @param 设置工资
 */
public void setSalary(int i) {
this.salary = i;
} /**
 * 
 * @return 返回保险金
 */
public int getInsurance() {
return insurance;
} /**
 * 
 * @param 设置保险金
 */
public void setInsurance(int i) {
this.insurance = i;
}
/**
 * 输出员工状况
 */
public void export() {
System.out.println("部门成员:" + name + "," + salary + "," + insurance);
}}这是俺自己写的代码,那个与员工的工作算保险金的俺自己写出来了,但是部门和公司汇总的实在是不会了。高手们帮忙看看!
然后就是有没有更好的写法,我这分了4个JAVA文件写。有的话大概的写一下或者是给点提示!谢谢哦!!

解决方案 »

  1.   

    哦,如果没记错的话那个company类里面已经被改的有点小乱了。汗一个先!自己先顶一下~~~
      

  2.   

    我给你一个建议啊 仅仅是我个人的看法啊 你要输出这样的效果,对吧?
    公司:MacroSoft,18500,1675 
    部门:R&D,13000,1100 
    部门成员:Jason,3000,600 
    部门成员:Peter,6000,300 
    部门成员:James,4000,200 
    部门:HR,5500,575 
    部门成员:Carol,2000,400 
    部门成员:Daisy,3500,175 
    但是我觉得部门成员,比如Jason吧 他不应该只有三个属性,这样的话你怎么把员工和部门合并在一起呢? 至少还有这个员工是不是合同工  是属于那个部门的   这些都应该是Employee的属性至于打印的时候  你可以单独给每个类 重写一个toString方法  到时候直接print就可以了   至于需不需要排序的话  最好加上  可以去看我的这篇blog:http://blog.csdn.net/justinavril/archive/2008/09/13/2924557.aspx
      

  3.   

    因为你帖子里的许多数据我不知道怎么回事
    你把整个需求发我邮箱吧  我周末做做看 给你完整的代码吧   平时上班还要写论文  没什么时间 
    [email protected]