很急很急 拜托了 java编程 子类和基类的问题。

设计了一个名为Person和它的两个子类名为Student和Employee。使Employee有Faculty和Staff两个子类。每个person有一个name,address, phone number, and email address。每个Student有一个相应的年级status( freshman,sophomore,junior, or senior)。定义status为常数。每一个employee都有office, salary, and date hired(办公室,工资和录用日期)。定义一个名为MyDate的类,包含字段年,月,日。每个faculty成员都有office hours and a rank。每个staff成员有一个title。在每个类中重写toString方法来显示class name和person’sname。
写一个测试程序创建一个人,学生,员工,教师和工作人员,并调用其的toString()方法。

尽量写简单一点、完整的调通的程序哦、拜托啦。

package zhidao;
/**
 * Person 类的子类
 * @author Administrator
 *
 */
public class Employee  extends Person{
    //每一个employee都有office, salary, and date hired(办公室,工资和录用日期)
    
    String office;//办公室
    int salary;    // 工资
    String hired;//录用日期
    
    public String toString(){
        String className = this.getClass().getCanonicalName();
        System.out.println(className);
        return className;
        
    }
    
}

package zhidao;
/**
 * Employee的子类
 * @author Administrator
 *
 */
public class Faculty extends Employee{
    public String toString(){
        String className = this.getClass().getCanonicalName();
        System.out.println(className);
        return className;
        
    }
}

package zhidao;
/**
 * 定义一个名为MyDate的类,包含字段年,月,日。每个faculty成员都有office hours and a rank
 * @author Administrator
 *
 */
public class MyDate {
    private String year;
    private String month;
    private String day;
    
    public String date(){

        return this.year + "年" + this.month +"月" +this.day + "日";

    }
    
    public String toString(){
        String className = this.getClass().getCanonicalName();
        System.out.println(className);
        return className;
        
    }
}


package zhidao;
/**
 *Person 父类    有两个子类 Student和Employee
 * @author Administrator
 *
 */
public class Person {
    private String name;
    private int address;
    private int phoneNumber;
    private int emailAddress; 
    
    public String toString(){
        String className = this.getClass().getCanonicalName();
        System.out.println(className);
        return className;
        
    }
    public static void main(String[] args) {
        Person p = new Person();
        p.toString();
    }
    
}


package zhidao;
/**
 * Employee的子类
 * @author Administrator
 *
 */
public class Staff extends Employee{
    private String title;
    
    public String toString(){
        String className = this.getClass().getCanonicalName();
        System.out.println(className);
        return className;
        
    }
}

package zhidao;
/**
 * Person 类的子类
 * @author Administrator
 *
 */
public class Student extends Person {
    private final static int freshman = 1;//定义常量  年级
    private final static int sophmore = 2;
    private final static int junior = 3;
    private final static int senior = 4;
    
    public void  status(int i){  //定义年级
        switch (i) {
        case 1: System.out.println(freshman+"");
            break;
        case 2: System.out.println(sophmore+"");
            break;
        case 3: System.out.println(junior+"");
            break;
        case 4: System.out.println(senior+"");
            break;

        default:
            break;
        }
    }
    
    public String toString(){
        String className = this.getClass().getCanonicalName();
        System.out.println(className);
        return className;
        
    }
}

package zhidao;

public class test {
    public static void main(String[] args) {
        //写一个测试程序创建一个人,学生,员工,教师和工作人员,并调用其的toString()方法。
        Student s = new Student();     //创建一个学生
        s.toString();
        Employee e = new Employee();    //创建一个员工
        e.toString();
        Faculty f = new Faculty();         //创建一个老师
        f.toString();
        Staff sf= new Staff();
        sf.toString();
        
    }
}

水平就这样了  看看能不能用  不能用就算了   好累!!!!!

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-11-24
10分啊 呵呵追问

想多给的,可是没有财富值了。

追答