用Java写代码:SaleManager是Employee的子类,Employee有:name,id, salary等属性;SaleManager则扩充了:销售收入salesRevenue和销售利润salesProfit两个属性。 要求每个数据都是私有,父类和子类均实现showMessage和构造方法。 测试类中,创建一个SaleManager,调用showMessage方法输出: 销售经理信息: 员工信息:姓名:张三;id号:10001;薪金:10000元; 扩展信息:销售收入:1000000元,销售利润:100000元。用3个窗口写
时间: 2024-02-25 22:56:22 浏览: 66
java代码-Employee.java
窗口1:Employee.java
```java
public class Employee {
private String name;
private int id;
private double salary;
public Employee(String name, int id, double salary) {
this.name = name;
this.id = id;
this.salary = salary;
}
public void showMessage() {
System.out.println("员工信息:");
System.out.println("姓名:" + name + ";id号:" + id + ";薪金:" + salary + "元;");
}
}
```
窗口2:SaleManager.java
```java
public class SaleManager extends Employee {
private double salesRevenue;
private double salesProfit;
public SaleManager(String name, int id, double salary, double salesRevenue, double salesProfit) {
super(name, id, salary);
this.salesRevenue = salesRevenue;
this.salesProfit = salesProfit;
}
public void showMessage() {
super.showMessage();
System.out.println("扩展信息:销售收入:" + salesRevenue + "元,销售利润:" + salesProfit + "元。");
}
}
```
窗口3:Test.java
```java
public class Test {
public static void main(String[] args) {
SaleManager sm = new SaleManager("张三", 10001, 10000, 1000000, 100000);
System.out.println("销售经理信息:");
sm.showMessage();
}
}
```
阅读全文