2-8练习问题
Employee.java:3: error: class EmployeeTest is public, should be declared in a file named EmployeeTest.java
public class EmployeeTest {
^
EmployeeTest.java:1: error: class Employee is public, should be declared in a file named Employee.java
public class Employee{
^
Note: Employee.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
在eclipse里可以正常运行,在练习里却提示这个错误,看不懂。
正在回答 回答被采纳积分+1
public class Employee{ //根据需求完成Employee类的定义 private int id; private String name; private double salary; public Employee(){ } public Employee(int id,String name,double salary){ this.id=id; this.name=name; this.salary=salary; } public void setId(int id){ this.id=id; } public int getId(){ return this.id; } 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; } }
import java.util.List;
import java.util.ArrayList;
public class EmployeeTest {
public static void main(String[] args) {
//定义ArrayList对象
List employeeList=new ArrayList();
//创建三个Employee类的对象
Employee employee1=new Employee(1,"张三",5000.0);
Employee employee2=new Employee(2,"李四",5500.0);
Employee employee3=new Employee(3,"赵六",4000.0);
//添加员工信息到ArrayList中
employeeList.add(employee1);
employeeList.add(employee2);
employeeList.add(employee3);
//显示员工的姓名和薪资
System.out.println("员工姓名 员工薪资");
for(int i=0;i<employeeList.size();i++){
System.out.println(((Employee) employeeList.get(i)).getName()+" "+((Employee) employeeList.get(i)).getSalary());
}
}
}
- 参与学习 人
- 提交作业 7317 份
- 解答问题 14452 个
想要入门学编程?多年一直活跃在编程语言排行版前列的Java是一个很好的选择。本路径将从Java基础语法、面向对象、常用工具类三部分,为你开启软件开发的大门!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星