(18 『编程题〕使用 Java 编程实现以下内容。 (1)编写 Employee 类,该类包含下列成员。 •四个受保护属性:name、number、address 和 salary; •一个构造方法:用于初始化 name、number 和 salary 属性; •两个公有成员方法:intr()实现雇员基本信息的输出,raiseSalary()实现按比例珠 工资的功能。 (2)编写 Manager 类,该类继承于 Employee 类。 ①为其添加下列内容: •两个私有属性:officeID和 bonus; •一个构造方法:带有 4个参数的构造方法,用于对除 bonus 属性外的所有其他属性进行初始化; 。公有方法:oifice1D 和 bonus 属性的相关 set 和get 方法。 基础上增加 10%的比例。 ②重写 Employee类的raisesalary 方法,经理工资的计算方法为在雇员工资涨橱的(3)编写 TemporaryEmployee 类,该类继承于 Employee类。 ①为其添加下列内容:•一个私有属性:hire Years; •构造方法:用于初始化该类的所有属性; 。公有方法:hireYears 属性的 set 和get 方法。 ②重写 Employee 类的 raiseSalary 方法,临时工的工资涨幅为正式雇员的 50%。
时间: 2024-03-23 19:42:30 浏览: 109
以下是Java代码实现:
```
// Employee类
public class Employee {
protected String name;
protected int number;
protected String address;
protected double salary;
public Employee(String name, int number, double salary) {
this.name = name;
this.number = number;
this.salary = salary;
}
public void intro() {
System.out.println("Name: " + name);
System.out.println("Number: " + number);
System.out.println("Address: " + address);
System.out.println("Salary: " + salary);
}
public void raiseSalary(double percent) {
salary *= (1 + percent);
}
}
// Manager类
public class Manager extends Employee {
private String officeID;
private double bonus;
public Manager(String name, int number, double salary, String officeID, double bonus) {
super(name, number, salary);
this.officeID = officeID;
this.bonus = bonus;
}
public void setOfficeID(String officeID) {
this.officeID = officeID;
}
public String getOfficeID() {
return officeID;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
public double getBonus() {
return bonus;
}
public void raiseSalary() {
salary *= 1.1;
salary += bonus;
}
}
// TemporaryEmployee类
public class TemporaryEmployee extends Employee {
private int hireYears;
public TemporaryEmployee(String name, int number, double salary, int hireYears) {
super(name, number, salary);
this.hireYears = hireYears;
}
public void setHireYears(int hireYears) {
this.hireYears = hireYears;
}
public int getHireYears() {
return hireYears;
}
public void raiseSalary() {
salary *= 1.5;
}
}
```
阅读全文