鱼C论坛

 找回密码
 立即注册
查看: 2656|回复: 1

面向对象的几个问题

[复制链接]
发表于 2022-3-26 21:38:35 | 显示全部楼层 |阅读模式
20鱼币
·(1)编写老师类,要求有属性:姓名name,年龄age,职称post,基本工资salary
·(2)编写业务方法:introduce(),实现输出一个教师的信息
·(3)编写教师类的三个子类:教授类(Professo)、副教授类、讲师类,工资级别分为:教授1.3、副教授1.2、讲师类1.1。再三个子类重写父类的introduce()方法
·(4)定义并初始化一个老师对象,调用业务方法,实现对象基本信息的后台打印。

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-3-27 23:26:45 | 显示全部楼层
来了啊,你这个没讲清楚,能说的清楚一点吗?
public class Teacher {
    public static void main(String[] args) {
        Introduce introduce = new Introduce();
        Teacher teacher = new Teacher();

        String name = "王芳芳";
        int age = 18;
        String post = "讲师";
        double salary = 0;
        if (post == "教授"){
            salary = introduce. professo();
        }else if (post == "副教授"){
            salary = introduce.assprofessor();
        }else if (post == "讲师"){
            salary = introduce.teacher();
        }
        teacher.Teacher(name,age,post,salary);

    }
    void Teacher(String name,int age,String post,double salary){
        System.out.println("名字是"+name);
        System.out.println("年龄是"+age);
        System.out.println("职业是"+post);
        System.out.println("工资有"+salary);
    }
    
}
class Introduce {
    double professo(){
        return 1.3;
    }
    double assprofessor(){
        return 1.2;
    }
    double teacher() {
        return 1.1;
    }
}
亲,这是不是你想要的呢?如果是请设置最佳答案啊!谢谢啦。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-28 11:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表