我要晕了、、、、
继承、
[解决办法]
public void setSalary(double salary) {
this.salary =salary*2;
System.out.println("经理的工资是"+salary);
}
public class Employee {
private String name; //姓名
private int age; //年龄
private float salary; //工资
/***
* 构造函数
*/
public Employee(String name,int age){
this.name = name;
this.age = age;
}
/***
* 设定工资的方法,在Employee里可以直接设置成空方法
* @param salary
*/
public void setSalary(float salary){
this.salary = salary;
}
/***
* 获得工资的方法
*/
public float getSalary(){
return this.salary;
}
}
class Manager extends Employee{
/***
* Manager的构造函数
*/
public Manager(String name, int age){
super(name,age);
}
@Override
public void setSalary(float salary){
super.setSalary(salary);
}
}
class Salesman extends Employee{
private float fixSalary = (float) 3000.0; //固定工资3000元每月
/***
* Salesman的构造函数
*/
public Salesman (String name, int age){
super(name,age);
}
/***
* 重写setSalary方法,这里的参数是营业额
* @param salesMoney
*/
@Override
public void setSalary(float salesMoney){
//假设销售人员的工资是基本工资加上销售额的10%提成
float salary = (float) (this.fixSalary + salesMoney * 0.1);
super.setSalary(salary);
}
}
class Worker extends Employee{
/***
* Salesman的构造函数
*/
public Worker (String name, int age){
super(name,age);
}
/***
* 重写setSalary方法,这里的参数工作时间
* @param daysOfWork
*/
@Override
public void setSalary(float daysOfWork){
//假设销售人员的工资是基本工资加上销售额的10%提成
float salary = (float) (daysOfWork * 100);
super.setSalary(salary);
}
}
public class Main {
public static void main(String[] args){
Manager manager = new Manager("张三",30);
manager.setSalary(10000); //经理的固定工资,一个月10000
Salesman salesMan = new Salesman("李四",25);
salesMan.setSalary(20000); //销售本月完成了20000的销售指标
Worker worker = new Worker("王五",22);
worker.setSalary(22); //工人本月共工作22个工作日
System.out.println("经理的工资:"+manager.getSalary());
System.out.println("销售的工资:"+salesMan.getSalary());
System.out.println("工人的工资:"+worker.getSalary());
}
}