编写老师类 * 1、要求有属性 name,age,职称post,基本工资salary * 2、编写方法 introduce() 实现输出一个教师的信息 * 3、编写教师类的三个子类:教授类、

package com.lmdedu.homework;
/**
 * 编写老师类
 * 1、要求有属性 name,age,职称post,基本工资salary
 * 2、编写方法  introduce()  实现输出一个教师的信息
 * 3、编写教师类的三个子类:教授类、副教授类、讲师类,奖金Bonus级别分别为1.3 1.2 1.1
 *    在三个子类中都有 重写 父类的introduce()
 * 4、定义并初始化一个老师对象,调用introduce()
 */
public class homework03 {
    public static void main(String[] args) {
        professor lmd = new professor("lmd",28,"副教授",2);
        System.out.println(lmd.introduce());
//        Teacher teacher = new associate_professor("lmd",28,"副教授",2);
//        associate_professor teach = (associate_professor)teacher;
//        System.out.println(teach.introduce());
    }
}

//老师类
class Teacher{
    //属性
    private String name;
    private int age;
    private String post;
    private double salary;

    public Teacher() {
    }

    public Teacher(String name, int age, String post, double salary) {
        this.name = name;
        this.age = age;
        this.post = post;
        this.salary = salary;
    }

    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 getPost() {
        return post;
    }

    public void setPost(String post) {
        this.post = post;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", post='" + post + '\'' +
                ", salary=" + salary +
                '}';
    }
    public String introduce(){
        return "姓名" + "\t" + getName() + "年龄"
                + getAge() + "职称" + getPost()
                +"基本工资" + getSalary();
    }
}

//教授类
class professor extends Teacher{
    private double Bonus = 1.3;

    public professor(String name, int age, String post, double salary) {
        super(name, age, post, salary);
        //Bonus = bonus;
    }

    public double getBonus() {
        return Bonus;
    }

    public void setBonus(double bonus) {
        Bonus = bonus;
    }

    public String introduce(){
        return super.introduce() + "奖金为" + getBonus();
    }
}

//副教授类
class associate_professor extends Teacher{
    private double Bonus = 1.2;

    public associate_professor(String name, int age, String post, double salary) {
        super(name, age, post, salary);
        //Bonus = bonus;
    }

    public double getBonus() {
        return Bonus;
    }

    public void setBonus(double bonus) {
        Bonus = bonus;
    }

    public String introduce(){
        return super.introduce() + "奖金为" + getBonus();
    }
}

//讲师类
class lecturer extends Teacher{
    private double Bonus = 1.1;

    public lecturer(String name, int age, String post, double salary) {
        super(name, age, post, salary);
        //Bonus = bonus;
    }

    public double getBonus() {
        return Bonus;
    }

    public void setBonus(double bonus) {
        Bonus = bonus;
    }

    public String introduce(){
        return super.introduce() + "奖金为" + getBonus();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值