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());
}
}
{
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 Employ
不然怎么用
不明白啊,另外把Employeetest改为Employee
{
name=n;
salary=s;
}
这个函数没有返回值,应该是构造函数吧
构造函数必须和类是同名的啊,你这里没有同名啊!!!!!