我做的代码有问题可是我却不知道为什么会有错,代码如下:
public abstract class Employee {
String name;
double basic;
String address;
public Employee(String name,double basic,String address){
this.name=name;
this.basic=basic;
this.address=address;
}
public void show(){
System.out.println("姓名:"+name);
System.out.println("地址:"+address);
System.out.println("薪资:"+basic);
}
public abstract void wages();
}
public class Director
extends Employee {
double transportAllowance;
double houseRentAllowance;
double dearnessAllowance;
double medicalAllowance;
double enterainmentAllowance;
double leave;
double netPay;
double lessPay;
public Director(String name, double basic, String address) {
super(name, basic, address);
}
public void show() {
super.show();
System.out.println("交通补贴:" + transportAllowance);
}
public void wages(double transportAllowance, double leave) {
double houseRentAllowance = basic * 0.2;
double dearnessAllowance = basic * 0.5;
double medicalAllowance = 4500;
double enterainmentAllowance = 5000;
double totalAmount = basic + houseRentAllowance + dearnessAllowance +
medicalAllowance + enterainmentAllowance + transportAllowance;
double lessPay = (leave <= 5) ? (0.25 * basic) : (0.5 * basic);
double netPay = totalAmount - lessPay;
System.out.println("工资总额:" + totalAmount);
System.out.println("净工资:" + netPay);
}
public void wages(double leave) {
double houseRentAllowance = basic * 0.08;
double dearnessAllowance = basic * 0.3;
double medicalAllowance = 1500;
double totalAmount = basic + houseRentAllowance + dearnessAllowance +
medicalAllowance;
double lessPay = (leave <= 5) ? (0.25 * basic) : (0.5 * basic);
double netPay = totalAmount - lessPay;
System.out.println("工资总额:" + totalAmount);
System.out.println("净工资:" + netPay);
}
}
public class Manager
extends Employee {
String department;
public Manager(String name,double basic,String address,String department){
super(name,basic,address);
this.department=department;
}
public void show(){
super.show();
System.out.println("部门:"+department);
}
public void wages() {
}
}
这段代码在红字处的错误是这个类不是抽象类不能被重写;蓝字处的错误是找不到这个符号!在黄色的地方提示的是这个错误:"Manager.java": wages() in untitled4.Manager cannot override wages() in untitled4.Employee; attempting to use incompatible return type; found : void, required: double at line 14, column 3
"Manager.java": cannot find symbol; symbol : method show(), location: class untitled4.Employee at line 11, column 11
"Manager.java": wages() in untitled4.Manager cannot override wages() in untitled4.Employee; attempting to use incompatible return type; found : void, required: double at line 14, column 3
还有一个我不明白的是在Director这个类中我在第一个wages方法中加入double leave后他就没有出现Director类不是抽象类不能被重写这个错误,而在第2个wages方法中加入double leave他就提示Director类不是抽象类不能被重写这个错误,这个是为什么啊??