public class task02 {
public static void main(String[] args) {
//创建employee类的对象
Employee staff = new Employee();
Employee prog = new Employee();
Employee desi = new Employee();
Employee arch = new Employee();
String[][] employees = {
{"10", "1", "段誉", "22", "3000","0","0"},
{"13", "2", "令狐冲", "32", "18000", "15000", "2000"},
{"11", "3", "任我行", "23", "7000","0","0"},
{"11", "4", "张三丰", "24", "7300","0","0"},
{"12", "5", "周芷若", "28", "10000", "5000","0"},
{"11", "6", "赵敏", "22", "6800","0","0"},
{"12", "7", "张无忌", "29", "10800", "5200","0"},
{"13", "8", "韦小宝", "30", "19800", "15000", "2500"},
{"12", "9", "杨过", "26", "9800", "5500","0"},
{"11", "10", "小龙女", "21", "6600","0","0"},
{"11", "11", "郭靖", "25", "7100","0","0"},
{"12", "12", "黄蓉", "27", "9600", "4800","0"}
};
// 创建新的数组
int salary[] = new int[employees.length];
int age[] = new int[employees.length];
int bonus[] = new int[employees.length];
int shares[] = new int[employees.length];
// 用新的数组将string转换为int值
for (int i = 0; i < employees.length; i++) {
age[i] = Integer.parseInt(employees[i][3]);
salary[i] = Integer.parseInt(employees[i][4]);
bonus[i] = Integer.parseInt(employees[i][5]);
shares[i] = Integer.parseInt(employees[i][6]);
}
for (int i = 0; i < employees.length; i++) {
switch (employees[i][0]) {
case "10":
staff.count ++;
staff.wageSum += salary[i];
staff.ageSum += age[i];
staff.bonusSum += bonus[i];
staff.sharesSum += shares[i];
break;
case "11":
prog.count ++;
prog.wageSum += salary[i];
prog.ageSum += age[i];
prog.bonusSum += bonus[i];
prog.sharesSum += shares[i];
break;
case "12":
desi.count ++;
desi.wageSum += salary[i];
desi.ageSum += age[i];
desi.bonusSum += bonus[i];
desi.sharesSum += shares[i];
break;
case "13":
arch.count ++;
arch.wageSum += salary[i];
arch.ageSum += age[i];
arch.bonusSum += bonus[i];
arch.sharesSum += shares[i];
break;
}
}
System.out.println("员工类型\t\t数量\t平均年龄\t\t平均薪资\t\t总收入");
int staffAvgWages = staff.getAvgWages(staff.wageSum, staff.count);
int staffAvgAge = staff.getAvgAge(staff.ageSum, staff.count);
int staffIncomSum = staff.getIncomSum(staff.wageSum, staff.bonusSum, staff.sharesSum);
System.out.println("普通员工" + "\t\t" + staff.count + "\t\t" + staffAvgAge + "\t\t\t" + staffAvgWages + "\t\t" + staffIncomSum );
int progAvgWages = prog.getAvgWages(prog.wageSum, prog.count);
int progAvgAge = prog.getAvgAge(prog.ageSum, prog.count);
int progIncomSum = prog.getIncomSum(prog.wageSum, prog.bonusSum, prog.sharesSum);
System.out.println("程序员" + "\t\t" + prog.count + "\t\t" + progAvgAge + "\t\t\t" + progAvgWages + "\t\t" + progIncomSum );
int desiAvgWages = desi.getAvgWages(desi.wageSum, desi.count);
int desiAvgAge = desi.getAvgAge(desi.ageSum, desi.count);
int desiIncomSum = desi.getIncomSum(desi.wageSum, desi.bonusSum, desi.sharesSum);
System.out.println("设计师" + "\t\t" + desi.count + "\t\t" + desiAvgAge + "\t\t\t" + desiAvgWages + "\t\t" + desiIncomSum );
int archAvgWages = arch.getAvgWages(arch.wageSum, arch.count);
int archAvgAge = arch.getAvgAge(arch.ageSum, arch.count);
int archIncomSum = arch.getIncomSum(arch.wageSum, arch.bonusSum, arch.sharesSum);
System.out.println("架构师" + "\t\t" + arch.count + "\t\t" + archAvgAge + "\t\t\t" + archAvgWages + "\t\t" + archIncomSum );
}
// 员工类
static class Employee {
int count = 0;
int wageSum = 0;
int ageSum = 0;
int bonusSum = 0;
int sharesSum = 0;
// 求平均工资方法
public int getAvgWages(int wageSum, int employeeSum) {
int avgwages = wageSum / employeeSum;
return avgwages;
}
// 求平均年龄方法
public int getAvgAge(int ageSum, int employeeSum) {
int avgAge = ageSum / employeeSum;
return avgAge;
}
// 求总收入方法
public int getIncomSum(int wageSum, int bonusSum, int sharesSum) {
int incomSum = wageSum + bonusSum + sharesSum;
return incomSum;
}
}
}