请问哪里出错了/
import java.util.List; import java.util.ArrayList; public class EmployeeTest { public static void main(String[] args) { //定义ArrayList对象 ArrayList clerkList=new ArrayList(); //创建三个Employee类的对象 Employee clerk1=new Employee("张三",5000.0); Employee clerk2=new Employee("李四",5500.0); Employee clerk3=new Employee("赵六",4000.0); //添加员工信息到ArrayList中 clerkList.add(clerk1); clerkList.add(clerk2); clerkList.add(clerk3); //显示员工的姓名和薪资 System.out.println("员工姓名 员工薪资"); for(int i=0;i<clerkList.size();i++){ System.out.println((Employee)(clerkList.get(i)).getName()+" "+((Employee)(clerkList.get(i)).getSalary())); } } }
public class Employee{ //根据需求完成Employee类的定义 private String name; private double salary; public Employee(){ } public Employee(String name,double salary){ this.setName(name); this.setSalary(salary); } public void setName(String name){ this.name=name; } public String getName(){ return this.name; } public void setSalary(double salary){ this.salary=salary; } public double getSalary(){ return this.salary; } }
正在回答 回答被采纳积分+1
上面有错修改了还是不对,如下
import java.util.List; import java.util.ArrayList; public class EmployeeTest { public static void main(String[] args) { //定义ArrayList对象 ArrayList clerkList=new ArrayList(); //创建三个Employee类的对象 Employee clerk1=new Employee("张三",5000.0); Employee clerk2=new Employee("李四",5500.0); Employee clerk3=new Employee("赵六",4000.0); //添加员工信息到ArrayList中 clerkList.add(clerk1); clerkList.add(clerk2); clerkList.add(clerk3); //显示员工的姓名和薪资 System.out.println("员工姓名 员工薪资"); for(int i=0;i<clerkList.size();i++){ System.out.println((Employee)(clerkList.get(i)).getName()+" "+(Employee)(clerkList.get(i)).getSalary()); } } }
请问哪里有问题?
提示信息
/7/4108252/110/2061/EmployeeTest.java:18: error: cannot find symbol
System.out.println((Employee)(clerkList.get(i)).getName()+" "+(Employee)(clerkList.get(i)).getSalary());
^
symbol: method getName()
location: class Object
/7/4108252/110/2061/EmployeeTest.java:18: error: cannot find symbol
System.out.println((Employee)(clerkList.get(i)).getName()+" "+(Employee)(clerkList.get(i)).getSalary());
^
symbol: method getSalary()
location: class Object
Note: /7/4108252/110/2061/EmployeeTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
- 参与学习 人
- 提交作业 7317 份
- 解答问题 14452 个
想要入门学编程?多年一直活跃在编程语言排行版前列的Java是一个很好的选择。本路径将从Java基础语法、面向对象、常用工具类三部分,为你开启软件开发的大门!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星