我在编下面的题,程序Manager中的public double zong()方法出现错误,大家进来了一起研究下,我还有很多地方不懂想请教大家呢,才学的,呵呵
编写一个程序,用于创建一个名为Employee(员工)的父类和两个名为Manager(经理)和Director(董事)的子类.Employee类包含3个属性和一个方法,属性为name(姓名),basic(基本工资)和address(家庭住址).方法名为show(),用于显示这些属性的值.Manager类有一个称为department(部门)的附加属性.Director类有一个称为transportAllowance(交通津贴)的附加属性,创建Manager和Director类的对象,并显示其详细信息
在上面的基础上,在Employee类中添加一个抽象方法以计算薪资总额.定义一个方法基于休假天数计算要从基本薪资中扣除的部分.计算薪资部分的公式为
lessPay=(leave<=5) ? (0.25*basic) : (0.5*basic)
Manager和Director类重写父类的的抽象方法
计算Manager的薪资总额的公式为:
totalAmount=basic+houseRentAllowance+dearnessAllowance+medicalAllowance
其中
houseRentAllowance为basic的8%
dearnessAllowance为basic的30%
medicalAllowance为1500
计算Director的薪资的总额的公式为:
totalAmount=basic+houseRentAllowace+dearnessAllowance+medicalAllowance+entertainmentAllowance+transportAllowance
其中
houseRentAllowance为basic的20%
dearnessAllowance为basic的50%
entertainmentAllowace为5000
该程序还应计算应付薪资,其公式为
NetPay=totalAmount-lessPay
应该编写一个方法来显示Name,Address,Basic,TotalPay和NetPay属性中存储的值
最后在主函数中定义Director类和Manager的对象,然后输出其相应信息
abstract class Employee
{
String name,address;
double basic;
double lessPay;
public abstract double zong();
double kou(int leave)
{
lessPay=(leave<=5)?(0.25*basic):(0.5*basic);
return lessPay;
}
}
class Manager extends Employee
{
char department;
double totalAmount;
public double zong()
{
this.totalAmount=this.basic+0.08*this.baisc+0.3*this.basic+1500;
return this.totalAmount;
}
double shiji()
{
return this.totalAmount-this.lessPay;
}
}
class Director extends Employee
{
double transportAllowance=2000.0;
double totalAmount;
public double zong()
{
this.totalAmount=this.basic+0.2*this.basic+0.5*this.basic+1500+5000+transportAllowance;
}
double shiji()
{
return this.totalAmount-this.lessPay;
}
}
class Example
{
public static void main(String args[])
{
Manager a=new Manager();
Director b=new Director();
a.name="张三";
a.address="沈阳";
a.basic=4000;
b.name="李四";
b.address="抚顺";
b.basic=10000;
a.zong();
a.kou(5);
a.shiji();
System.out.println("Manager的具体情况:"+a.name+a.address+a.zong()+a.lessPay+a.shiji());
b.zong();
b.kou(8);
b.shiji();
System.out.println("Director的具体情况:"+b.name+b.address+b.zong()+b.lessPay+b.shiji());
}
}