这道java编程题怎么做?

 我来答
mimiba212
2020-02-22 · TA获得超过413个赞
知道小有建树答主
回答量:1504
采纳率:64%
帮助的人:85.9万
展开全部
public class Employee {

private String id;
private String name;
private double salary;
private int holiday;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}

public int getHoliday() {
return holiday;
}

public void setHoliday(int holiday) {
this.holiday = holiday;
}

/**
* 普通职员的工资计算方法
* @return
*/
public double salaryCut(){
double factSalaryCut=0.0d;
if (holiday<=5){
factSalaryCut=salary*(1-0.75);
}else{
factSalaryCut=salary*(1-0.5);
}
return factSalaryCut;
}
}
public class Manager extends Employee {
private static int medicalExpenses = 500;

public double salaryCompute4Manager(){
double firstPart = super.salaryCut();
double secondPart = getSalary()+(getSalary()*0.2)+(getSalary()*0.05)+medicalExpenses;
return secondPart-firstPart;
}
}

public class Director extends Employee {
private static int medicalExpenses = 200;
public double salaryCompute4Director(){
double firstPart = super.salaryCut();
double secondPart = getSalary()+(getSalary()*0.4)+(getSalary()*0.3)+medicalExpenses;
return secondPart-firstPart;
}
}

public class SalaryComputerMain {
public static void main(String[] args) {
Employee emp1 = new Employee();
emp1.setId("E01");
emp1.setName("王大毛");
emp1.setSalary(3000);
emp1.setHoliday(4);
System.out.println("员工:"+emp1.getName()+"的实发工资为:"+(emp1.getSalary()-emp1.salaryCut()));
Manager manager = new Manager();
manager.setId("E02");
manager.setName("王福林");
manager.setSalary(8000);
manager.setHoliday(5);
System.out.println("员工:"+manager.getName()+"的实发工资为:"+(manager.salaryCompute4Manager()));
Director director = new Director();
director.setId("E03");
director.setName("王健林");
director.setSalary(12000);
director.setHoliday(6);
System.out.println("员工:"+director.getName()+"的实发工资为:"+(director.salaryCompute4Director()));

}
}
静心写java
2020-02-22 · 长的肉肉的,说说娱乐的事!
静心写java
采纳数:40 获赞数:29

向TA提问 私信TA
展开全部
用抽象类去做是一个不错的选择
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式