一个计算薪水的程序有错误,大家帮忙看看
class Employeetest
{
private String name;
private double salary;
public Employee(String n,double s)
{
name=n;
salary=s;
}
public String getname()
{
return name;
}
public double getsalary()
{
return salary;
}
public void raisesalary(double bypercent)
{
double raise=salary*bypercent/100;
salary+=raise;
}
}
将每个雇员的薪水提高5%
class Employ
{
public static void main(String args[])
{
Employee [] staff=new Employee[3];
staff[0]=new Employee( "jay ",500);
staff[1]=new Employee( "kay ",100);
staff[2]=new Employee( "boo ",200);
for(Employee e : staff)
e.raisesalary(5);
for(Employee e : staff)
System.out.println(( "name= "+e.getname()+ ",salary= "+e.salary());
}
}
------解决方案--------------------我这不能运行,但首先看你都没有public class,至少先把class Employ 改为
public class Employ
不然怎么用
------解决方案--------------------再看你的 class Employeetest 构造函数也写的不对饿
------解决方案--------------------for(Employee e : staff)
不明白啊,另外把Employeetest改为Employee