一段有错的代码,来源于书上的
我学习java,书上有段代码,但我运行起来有错误,请高手指点哈,谢谢!
import java.util.*;
public class EmployeeSortTest
{
public static void main(String[] args)
{
Employee[] staff=new Employee[3];
staff[0]=new Employee("Harry Hacker",35000);
staff[1]=new Employee("Carl Cracker",75000);
staff[2]=new Employee("Tony Tester",38000);
Arrays.sort(staff);
for(int i=0;i<staff.length;i++)
{
Employee e=staff[i];
System.out.println("name="+e.getName()+",salary="+e.getSalary());
}
}
}
class Employee implements Comparable
{
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;
}
public int compareTo(Object otherObject)
{
Employee other=(Employee)otherObject;
if(salary<other.salary) return -1;
if(salary>other.salary) return 1;
return 0;
}
}
问题点数:20、回复次数:3Top
1 楼ntzls()回复于 2004-09-04 15:01:10 得分 20
public Employee(String n,double s)
{//<==
name=n;
salary=s;
}//:-)
Top
2 楼whbxm2000(学星,向星,摘星,披星)回复于 2004-09-04 15:15:08 得分 0
除了楼上说得()-->{}
看不出什么错。。。
??Top
3 楼shangqiao(伤桥(千万不要理解为我可怜桥,是“伤心桥下”的缩写))回复于 2004-09-04 15:46:52 得分 0
晕,谁说有错了,除了楼上说得,没有一点错,俺都试了Top




