欧卡2中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

需要三步,才能开始

只需两步,慢速开始

玩欧卡就用莱仕达V99方向盘欧卡2入门方向盘选莱仕达V9莱仕达折叠便携游戏方向盘支架欢迎地图Mod入驻
查看: 5785|回复: 0
收起左侧

各位帮忙改进下代码

[复制链接]
terkcov 发表于 2012-1-7 02:35 | 显示全部楼层 |阅读模式
public class Demo_9 {
    public static void main(String[] args) {
        Teacher teacher = new Teacher(11111,"张三", "男", 25, "讲师");
        teacher.display();
        Student student = new Student(9922, "李四", "男", 21, "公寓");
        student.display();
    }

}

abstract class  Person{
    protected String name;
    protected String sex;
    protected int age;
    protected String personInfo;
    abstract String getPersonInfo();
    public void display(){
        javax.swing.JOptionPane.showMessageDialog(null,personInfo);
    }
}

class Teacher extends Person{
    protected int tnumbers;
    protected String title;
   

    public Teacher(int tnumbers, String name, String sex, int age, String title){
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.tnumbers = tnumbers;
        this.title = title;
        personInfo=getPersonInfo();
    }
    public String getPersonInfo(){
        return
          "  职工号  " +tnumbers+ " 名字 " +name
        + "  性别  " +sex
        + "  年龄  " +age
        + "  职称  " +title;
    }
   

}

class Student extends Person{
    protected int snumbers;
    protected String address;
    public Student(int snumbers, String name, String sex, int age, String address){
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.snumbers = snumbers;
        this.address = address;
        personInfo=getPersonInfo();
    }
    public String getPersonInfo(){
        return
          " 学号   " +snumbers
        + " 名字   " +name
        + "  性别  " +sex
        + "  年龄  " +age
        + "  家庭住址  " +address;
    }
}

联系我们|手机版|欧卡2中国 ( 湘ICP备11020288号-1 )

GMT+8, 2024-12-27 15:38 , Processed in 0.030814 second(s), 8 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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