假设一个公司的员工分为志愿者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-01 09:16:09 浏览: 131
以员工类为父类,经理、工人类均继承该类。设计属性:姓名、工龄,方法:计算工资
ing方法返回Hourly类的信息,请补充toString方法的方法体。
以下是代码实现:
```java
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 + "\nAddress: " + address + "\nPhone: " + phone;
}
}
public class Volunter extends StuffMember {
public Volunter(String ename, String eaddress, String iphone) {
super(ename, eaddress, iphone);
}
public double pay() {
return 0.0;
}
}
public class Employee extends StuffMember {
private String socialSecurityNumber;
private double payRate;
public Employee(String ename, String eaddress, String iphone, String ssn, double rate) {
super(ename, eaddress, iphone);
socialSecurityNumber = ssn;
payRate = rate;
}
public String toString() {
return super.toString() + "\nSocial Security Number: " + socialSecurityNumber;
}
public double pay() {
return payRate * 2500.0;
}
}
public class Excutive extends Employee {
private double bonus;
public Excutive(String ename, String eaddress, String iphone, String ssn, double rate, double b) {
super(ename, eaddress, iphone, ssn, rate);
bonus = b;
}
public double pay() {
double payment = super.pay() + bonus;
bonus = 0.0;
return payment;
}
}
public class Hourly extends Employee {
private double hourWorked;
public Hourly(String ename, String eaddress, String iphone, String ssn, double rate, double hours) {
super(ename, eaddress, iphone, ssn, rate);
hourWorked = hours;
}
public String toString() {
return super.toString() + "\nHours Worked: " + hourWorked;
}
public double pay() {
double payment = super.payRate * hourWorked;
hourWorked = 0.0;
return payment;
}
}
```
阅读全文