2 yyqkn2015 yyqkn2015 于 2016.03.23 00:08 提问

有一个关于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
                + "]";
    }



}

7个回答

yyqkn2015
yyqkn2015   2016.03.25 17:10
已采纳

图片说明

yyqkn2015
yyqkn2015   2016.03.23 00:10

这是题目!!!!!

enpterexpress
enpterexpress   2016.03.23 10:56

那里有问题

yyqkn2015
yyqkn2015 在测试类中通过printScore方法输出的时候一直有错误,不知道怎么改;还有我没有通过数组输入学生的信息,那我求最高分的时候的方法根据我测试类里面写的话该如何定义?
一年多之前 回复
Royal_lr
Royal_lr   Ds   Rxr 2016.03.23 15:55

一直有错误,,是什么错误,,说清楚

yyqkn2015
yyqkn2015 已经做出来了,谢谢你的解答
一年多之前 回复
ganhaiqiang420
ganhaiqiang420   2016.03.23 16:16

你是要一套现成的代码还是帮你改bug?

yyqkn2015
yyqkn2015 已经做出来了,谢谢你的解答
一年多之前 回复
ganhaiqiang420
ganhaiqiang420   2016.03.23 16:24

你这代码写得糟透了

yyqkn2015
yyqkn2015 是的啊,我全给改了,简洁很多没有冗余了,很谢谢你的建议
一年多之前 回复
tanjunchen
tanjunchen   2016.03.24 00:12

代码好乱 拓展性差 没有系统化

yyqkn2015
yyqkn2015 恩恩,已经改了,谢谢你的意见
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!