这道java编程题怎么做?
展开全部
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()));
}
}
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()));
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询