黑马程序员技术交流社区
标题:
怎么运行是老是出错啊
[打印本页]
作者:
刘侠光
时间:
2011-12-12 10:56
标题:
怎么运行是老是出错啊
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 Crarker",75000);
staff[2]=new Employee("Tony Tester",38000);
Arrays.sort(staff);
for(Employee e:staff)
System.out.println("name"=+e.getName()+",salary="+e.getSalary());
}
}
class Employee implements Comparable<Employee>
{
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 raisa=salary*byPercent/100;
salary+=raisa;
}
public int compareTo(Employee other)
{
if(salary<other.salary)return -1;
if(salary>other.salary)return 1;
return 0;
}
private String name;
private double saalary;
}
作者:
吴上储
时间:
2011-12-12 11:07
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 Crarker",75000);
staff[2]=new Employee("Tony Tester",38000);
Arrays.sort(staff);
for(Employee e:staff)
System.out.println
("name"=+
e.getName()+",salary="+e.getSalary());
}
}
class Employee implements Comparable<Employee>
{
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 raisa=salary*byPercent/100;
salary+=raisa;
}
public int compareTo(Employee other)
{
if(salary<other.salary)return -1;
if(salary>other.salary)return 1;
return 0;
}
private String name;
private double
saalary;
}
作者:
zoufan7410
时间:
2011-12-12 11:14
看到了,你这有三个错误,第一个是你的private double saalary; 这个变量多写了一个a;
for(Employee e:staff)
System.out.println("name"=+e.getName()+",salary="+e.getSalary()); // name 这里的= 号写在了外面应该是"name = "+e.getName()+",
public double getSalary()
{
return salary(); //这里你写错了,salary 是属性,不是方法;
}
这此错误都是书写错误啊,你应该自己解决的哦。
作者:
应国炎
时间:
2011-12-12 11:14
本帖最后由 应国炎 于 2011-12-12 11:18 编辑
不知道你提示什么错误
1 你 System.out.println("name"=+e.getName()+",salary="+e.getSalary());里的=号要放括号里面去
2 private double saalary; saalary是不是写错了?
3 如果提示有符号: 变量 Arrays
位置: 类 Test
Arrays.sort(xxx);
类型的错误,则是没有导入相应的包
4 还有return salary; 是变量,不是方法 (刚才忘记写上了。重新编辑了一下)
作者:
唐秀启
时间:
2011-12-12 11:26
本帖最后由 benbenqi 于 2011-12-12 11:28 编辑
import java.util.*;//1如果用高级编辑器的话,会自动导入,如果记事本,EditPlus等工具需要手动输入
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 Crarker",75000);
staff[2]=new Employee("Tony Tester",38000);
Arrays.sort(staff);
for(Employee e:staff)
System.out.println("name="+e.getName()+",salary="+e.getSalary());//2 "name"=+
}
}
class Employee implements Comparable<Employee>
{
private String name;
private double salary;//3定义了saalary,而下面却用了salary变量 不同名变量
public Employee(String n, double s )
{
name=n;
salary=s;//3
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary; //4返回的是salary变量的值,salary()是函数
}
public void raiseSalary(double byPercent)
{
double raisa=salary*byPercent/100;
salary+=raisa;
}
public int compareTo(Employee other)
{
if(salary<other.salary)return -1;
if(salary>other.salary)return 1;
return 0;
}
}
作者:
wsssx
时间:
2011-12-12 11:35
提示:
作者被禁止或删除 内容自动屏蔽
作者:
lucky_xingxing
时间:
2011-12-12 14:56
{:soso_e136:}
作者:
李明
时间:
2011-12-12 15:03
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 Crarker",75000);
staff[2]=new Employee("Tony Tester",38000);
Arrays.sort(staff);
for(Employee e:staff)
System.out.println("name"=+e.getName()+",salary="+e.getSalary());//=号放在""里面
}
}
class Employee implements Comparable<Employee>
{
double salary ;//要定义在前面。
public Employee(String n, double s )
{
name=n;
salary=s;
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary(); //salary(),取值是不用()的。
}
public void raiseSalary(double byPercent)
{
double raisa=salary*byPercent/100;
salary+=raisa;
}
public int compareTo(Employee other)
{
if(salary<other.salary)return -1;
if(salary>other.salary)return 1;
return 0;
}
private String name;
private double saalary; //要定义在前面,否则会出错。
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2