亲爱的耀哥哥 2016-03-22 16:08 采纳率: 100%
浏览 1703
已采纳

有一个关于Java的小题目,做了好久做不出来,还请大神帮我

这是题目

 package com.ustcsoft.javatraining2016.homework1.zhaoyao;

public class homework1 {

    public static void main(String[] args) {
        Student student = new Student();
        Student student2 = new Student();
        Student student3 = new Student();
        Teacher teacher = new Teacher();
        Parent parent = new Parent();
        student.setStu_no(0001);
        student.setName("张三");
        student.setAge(16);
        student.setAddress("合肥市长江路0001号");
        student.setClassRoom("初三三班");
        student.setSchoolName("合肥一中");
        student.setScore(95);
        student2.setName("飞飞");
        student3.setName("晓婷");
        System.out.println(student.getName()+"("+student.getStu_no()+")"+":"+student.printScore(student.getScore()) +"\t"+student2.getName()+"("+student2.getStu_no()+")"+":"+student2.printScore(61)+"\t"+student3.getName()+"("+student3.getStu_no()+")"+":"+student3.printScore(55));


        System.out.println(student.toString());

        System.out.println();

        teacher.setName("李四");
        teacher.setAge(40);
        teacher.setAddress("合肥是长江西路0002号");
        teacher.setBonus(2000.0);
        teacher.setSchoolName("合肥一中");
        System.out.println(teacher.toString());

        System.out.println();

        parent.setName("王五");
        parent.setAge(41);
        parent.setAddress("合肥市长江西路0001号");

        System.out.println(parent.toString());





    }

}

    abstract class  Person{
    private String name;
    private int age;
    private String address;
    public abstract void eat() ;
    public abstract void work();
    }

interface Students{
    public void exam();
}

interface Teachers{
    public void prepareLessons();
}

interface Parents{
    public void breed();
}
 package com.ustcsoft.javatraining2016.homework1.zhaoyao;

public class Student extends Person implements Students{
    private String name;
    private String address;
    private int stu_no;
    public int getStu_no() {
        return stu_no;
    }

    private float score;
    private String classRoom;
    private String schoolName;

    public Student(String name, int age, String address, int stu_no,
            float score, String classRoom, String schoolName) {
        super();
        this.name = name;
        this.age = age;
        this.address = address;
        this.stu_no = stu_no;
        this.score = score;
        this.classRoom = classRoom;
        this.schoolName = schoolName;
    }

    public Student() {
        // TODO Auto-generated constructor stub
    }

    private int age;
    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public String getAddress() {
        return address;
    }


    public float getScore() {
        return score;
    }

    public String getClassRoom() {
        return classRoom;
    }

    public String getSchoolName() {
        return schoolName;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setStu_no(int stu_no) {
        this.stu_no = stu_no;
    }

    public void setScore(float score) {
        this.score = score;
    }

    public void setClassRoom(String classRoom) {
        this.classRoom = classRoom;
    }

    public void setSchoolName(String schoolName) {
        this.schoolName = schoolName;
    }

    @Override
    public void exam() {
        // TODO Auto-generated method stub
        System.out.println("考试");

    }

    @Override
    public void eat() {
        // TODO Auto-generated method stub
        System.out.println("吃饭");
    }

    @Override
    public void work() {
        // TODO Auto-generated method stub
        System.out.println("工作(学习)");
    }

    public  void printScore(float f){
    float num=f;
    String str;

    if(num>=90){
      str="优秀";

    }else if(num>=80){
      str="优良";
    }else if(num>=70){
      str="良好";

    }else if(num>=60){
      str="合格";

    }else{
      str="差";

    }
    System.out.println("成绩是 " + str);

    }

    public void bestStudent(int i){
        int j = i;
    }


    @Override
    public String toString() {
        return "Student [name=" + name + ", address=" + address + ", stu_no="
                + stu_no + ", score=" + score + ", classRoom=" + classRoom
                + ", schoolName=" + schoolName + ", age=" + age + "]";
    }








}

 package com.ustcsoft.javatraining2016.homework1.zhaoyao;

public class Teacher extends Person implements Teachers{
    private String name;
    private int age;
    private String address;
    private double bonus;
    private String schoolName;
    public String getSchoolName() {
        return schoolName;
    }

    public void setSchoolName(String schoolName) {
        this.schoolName = schoolName;
    }

    public Teacher(String schoolName) {
        super();
        this.schoolName = schoolName;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setBonus(double d) {
        this.bonus = d;
    }

    public Teacher(String name, int age, String address, float bonus) {
        super();
        this.name = name;
        this.age = age;
        this.address = address;
        this.bonus = bonus;
    }

    public Teacher(String name, int age, String address) {
        super();
        this.name = name;
        this.age = age;
        this.address = address;
    }

    public Teacher() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void prepareLessons() {
        // TODO Auto-generated method stub
        System.out.println("备课");
    }

    @Override
    public void eat() {
        // TODO Auto-generated method stub
        System.out.println("吃饭");
    }

    @Override
    public void work() {
        // TODO Auto-generated method stub
        System.out.println("工作");
    }

    public void bestStudent(getScore(),getScore(),getScore()){

    }

    @Override
    public String toString() {
        return "Teacher [name=" + name + ", age=" + age + ", address="
                + address + ", bonus=" + bonus + ", schoolName=" + schoolName
                + "]";
    }



}

 package com.ustcsoft.javatraining2016.homework1.zhaoyao;

public class Parent extends Person implements Parents{
    private String name;
    private int age;
    private String address;

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Parent(String name, int age, String address) {
        super();
        this.name = name;
        this.age = age;
        this.address = address;
    }

    public Parent() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void breed() {
        // TODO Auto-generated method stub
        System.out.println("养育");
    }

    @Override
    public void eat() {
        // TODO Auto-generated method stub
        System.out.println("吃饭");
    }

    @Override
    public void work() {
        // TODO Auto-generated method stub
        System.out.println("工作");
    }

    @Override
    public String toString() {
        return "Parent [name=" + name + ", age=" + age + ", address=" + address
                + "]";
    }



}

  • 写回答

5条回答 默认 最新

  • 亲爱的耀哥哥 2016-03-25 09:10
    关注

    图片说明

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。