还是存储下面这个表格的数据,但使用另一种方法来做。
用javabean和一维数组的方法来做,示例代码如下:
/*先创建一个类,其实就是创建好一个只有各属性列的空表格*/
class Employees {
private int id;
private String name;
private int age;
private String job;
private String hiredate;
public Employees(int id, String name, int age, String job, String hiredate) {
this.id = id;
this.name = name;
this.age = age;
this.job = job;
this.hiredate = hiredate;
}
@Override
public String toString() {
return "Employees{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", job='" + job + '\'' +
", hiredate='" + hiredate + '\'' +
'}';
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public String getHiredate() {
return hiredate;
}
public void setHiredate(String hiredate) {
this.hiredate = hiredate;
}
}
/*然后再为通过这个类来创建实例化的对象,每一个实例对象就是表格的一行*/
public class Test002 {
public static void main(String[] args) {
Employees[] employee ={
new Employees(1001,"高 淇",18,"讲 师","02-14"),
new Employees(1002,"高小七",19,"助 教","10-10"),
new Employees(1003,"高小八",20,"班主任","05-05")
};
for(Employees temp: employee){
System.out.println(temp);
}
}
}
运行结果: