Person类,有Student类和Employee类继承Person,
而Employee类又被教员类Teacher类和职员类Staff类继承。
每个人都有姓名、地址、电话号码和电子邮件地址。
学生有年级状态(大一到大四)。
雇员有办公室(office)、工资(salary)和受聘日期(dateOfEmployee)。
教员有办公时间(wordTime)和级别(level)。
职员有职位(job)。
覆盖每个类的toString()方法,显示相应的类名和人名。
编写一个测试程序,创建Student、Employee、Teacher和Staff,并且调用它们的toString()方法。
二、在一的基础上改进
1.按名字搜索某个人,找到的打印出来。
2.按雇员的入职日期查找某个时间段内的资料。
3.按名字删除某人
三、在一堆有Student,Teacher,Staff的数据中,删除"大三"的学生
第一步已经敲出来了,第二步怎么用for遍历,跪求大神指教!!!
package jicheng1;
public class ch08 {
public static void main(String[] args) {
Person person = new Person("Jack","4区5 220" ,"18059125704","1039572808@qq.com");
Student student = new Student("Nike", "4区5 221","18059125705", "1039572809@qq.com",Student.one);
Employee employee = new Employee("Mark","4区5 601","18059125706","1039572810@qq.com","大层楼409","8000","2015.5.20");
Teacher teacher = new Teacher("Bill","4区5 602","1805912507","1039572811@qq.com","大层楼410", "10000","2015.5.21","早上8点至下午4点","教授");
Staff staff = new Staff("William","4区5 603","1805912508","1039572812@qq.com","大层楼411", "12000","2015.5.22","教务主任");
System.out.println("类名:"+person.getClass().getName()+person.toString());
System.out.println("类名:"+student.getClass().getName()+student.toString());
System.out.println("类名:"+employee.getClass().getName()+employee.toString());
System.out.println("类名:"+teacher.getClass().getName()+teacher.toString());
System.out.println("类名:"+staff.getClass().getName()+staff.toString());
}
}
class Person{
protected String name,address,telNum,email;
public Person(String name,String address,String telNum,String email){
this.name = name;
this.address = address;
this.telNum =telNum;
this.email = email;
}
public String getName(){
return name;
}
public String getAddress(){
return address;
}
public String getTelNum(){
return telNum;
}
public String getEmail(){
return email;
}
public String toString(){
return "人名"+this.getName();
}
}
class Student extends Person{
protected int grade;
final static int one = 1,two = 2,three = 3,four = 4 ;
public Student(String name,String address,String telNum,String email,int grade){
super(name,address,telNum,email);
this.grade = grade;
}
public int findGrade(int grade){
return grade;
}
public int getGrade(){
return grade;
}
public String toString(){
return "人名"+this.getName();
}
}
class Employee extends Person{
protected String office,salary,dataOfEmployee;
public Employee(String name,String address,String telNum,String email,String office,String salary,String dataOfEmployee){
super(name,address,telNum,email);
this.office = office;
this.salary = salary;
this.dataOfEmployee = dataOfEmployee;
}
public String getOffice(){
return office;
}
public String getSalary(){
return salary;
}
public String getDataOfEmployee(){
return dataOfEmployee;
}
public String toString(){
return "人名"+this.getName();
}
}
class Staff extends Employee{
protected String job;
public Staff(String name,String address,String telNum,String email,String office,String salary,String dataOfEmployee,String job){
super(name,address,telNum,email,office,salary,dataOfEmployee);
this.job = job;
}
public String getJob(){
return job;
}
public String toString(){
return "人名"+this.getName();
}
}
class Teacher extends Employee{
protected String wordTime,level;
public Teacher(String name,String address,String telNum,String email,String office,String salary,String dataOfEmployee,String wordTime,String level){
super(name, address, telNum, email, office, salary, dataOfEmployee);
this.wordTime = wordTime;
this.level = level;
}
public String getWordTime(){
return wordTime;
}
public String getLevel(){
return level;
}
public String toString(){
return "人名"+this.getName();
}
}