栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

本章作业(面向对象高级)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

本章作业(面向对象高级)

(1)定义一个Person类{name,age,job},初始化Person对象数组,有三个person对象,并按照age从大到小进行排序,使用冒泡排序

public class Test {
    public static void main(String[] args) {
        Person[] person = new Person[3];
        person[0] = new Person("jack", 18, "it");
        person[1] = new Person("karry", 22, "idol");
        person[2] = new Person("cyn", 20, "chairman");

        //从大到小排序:
        for (int i = 0; i < person.length-i; i++) {
            for (int j  = 0; j < person.length-i-1;j++){
                if (person[j].getAge() 

 

(2)编写老师类

(1)要求有属性“姓名name”,“年龄age”,“职称”,“基本工资salary”

(2)编写业务方法,introduce(),实现输出一个教室的信息

(3)编写教师类的三个子类:教授类,副教授类,讲师类。工资级别分别为:教授为1.3,副教授为1.2,讲师类1.1.在三个子类里都重写父类的introduce()方法。

(4)定义并初始化一个老师对象,调用业务方法,实现对象基本信息的后台打印

  • Teacher类:

public class Teacher {
    private String name;
    private int age;
    private String post;
    private double 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;
    }

    public C(String name, int age, String post, double salary) {
        this.name = name;
        this.age = age;
        this.post = post;
        this.salary = salary;
    }
    public void introduce(){
        System.out.print("姓名"+name+"t"+"年龄"+age+"t"+"职称"+post+"t"+"工资"+salary);
    }
}
  • 教授类:

public class A extends Teacher {
    private double score;

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

    public void introduce(){
        super.introduce();
        System.out.println("t级别"+score);
    }
}

.....其余类和教授类一样

测试类:

public class Test{
    public static void main(String[] args){
        A a = new A("JACK",55,"教授",10000,1.4);
        a.introduce();
    }
}

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/632107.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号