假设一个公司的员工分为志愿者Volunter和普通员工Employee,请先设计一个StuffMember的抽象类作为不同类型员工的父类,包含员工都具有的name,address以及phone属性(建议是public 或者是protected类型)。且:(1)需要建议以下格式的构造函数,并补充构造函数内的语句Public StuffMember(String ename, String eaddress,String iphone)(2)需要构造一个抽象方法:public abstract double pay();(3) 需要建立一个toString方法返回StuffMember的信息,请补充toString方法的方法体Public String toString(){}完成Volunter类,该类继承了StuffMember的抽象类并需要重载父类的pay()方法.(1) Volunter类中的pay方法返回一个浮点的0值就可以了。(2) 请显示定义Volunter类的带参数的构造函数。完成有薪资的Employee类,该类继承了StuffMember的抽象类,并含有自己的属性社会保险号String 类型的sccialSecurityNumber,和酬金率double 类型的payRate。(1)请建立5个参数的构造函数。(2) 请需要建立一个toString方法返回Employee的信息,请补充toString方法的方法体。(3) 建立Employee类的pay() 方法,该方法只返回员工的payRate*2500。建立Excutive类继承了Employee类,并包含一个double类型的奖金属性bonus。(1) 建立Excutive类的包含6个参数的构造函数(2) 重构pay()方法,需要实现工资计算Payment=super.pay() +bonus; Bonus=0;完成按小时付钱的员工类Hourly类,该类继承了Employee类,并包含一个double类型的奖金属性double hourWorked。(1) 建立Hourly类的包含6个参数的构造函数(2) 重构pay()方法,需要实现工资计算Payment=super.payRate * hourWorked; hourWorked=0;(3) 建立toStr
时间: 2024-02-03 19:12:07 浏览: 143
以员工类为父类,经理、工人类均继承该类。设计属性:姓名、工龄,方法:计算工资
uct方法返回Hourly的信息,请补充toString方法的方法体。
```
public abstract class StuffMember {
protected String name;
protected String address;
protected String phone;
public StuffMember(String ename, String eaddress, String iphone) {
name = ename;
address = eaddress;
phone = iphone;
}
public abstract double pay();
public String toString() {
return "Name: " + name + ", Address: " + address + ", Phone: " + phone;
}
}
public class Volunter extends StuffMember {
public Volunter(String name, String address, String phone) {
super(name, address, phone);
}
public double pay() {
return 0.0;
}
}
public class Employee extends StuffMember {
protected String socialSecurityNumber;
protected double payRate;
public Employee(String name, String address, String phone, String ssn, double rate) {
super(name, address, phone);
socialSecurityNumber = ssn;
payRate = rate;
}
public String toString() {
return super.toString() + ", SSN: " + socialSecurityNumber + ", Pay Rate: " + payRate;
}
public double pay() {
return payRate * 2500;
}
}
public class Excutive extends Employee {
private double bonus;
public Excutive(String name, String address, String phone, String ssn, double rate, double bonus) {
super(name, address, phone, ssn, rate);
this.bonus = bonus;
}
public double pay() {
double payment = super.pay() + bonus;
bonus = 0.0;
return payment;
}
}
public class Hourly extends Employee {
private double hourWorked;
public Hourly(String name, String address, String phone, String ssn, double rate, double hourWorked) {
super(name, address, phone, ssn, rate);
this.hourWorked = hourWorked;
}
public double pay() {
double payment = super.payRate * hourWorked;
hourWorked = 0.0;
return payment;
}
public String toString() {
return super.toString() + ", Hours worked: " + hourWorked;
}
}
```
阅读全文