yyqkn2015
亲爱的耀哥哥
采纳率75%
2016-03-22 16:08 阅读 1.7k
已采纳

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

5

这是题目

 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 亲爱的耀哥哥 2016-03-25 09:10

    图片说明

    点赞 评论 复制链接分享
  • yyqkn2015 亲爱的耀哥哥 2016-03-22 16:10

    这是题目!!!!!

    点赞 评论 复制链接分享
  • enpterexpress 把分全给哥 2016-03-23 02:56

    那里有问题

    点赞 评论 复制链接分享
  • Royal_lr Royal_lr 2016-03-23 07:55

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

    点赞 评论 复制链接分享
  • ganhaiqiang420 ganhaiqiang420 2016-03-23 08:16

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

    点赞 评论 复制链接分享
  • ganhaiqiang420 ganhaiqiang420 2016-03-23 08:24

    你这代码写得糟透了

    点赞 评论 复制链接分享
  • tanjunchen 远方的飞猪 2016-03-23 16:12

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

    点赞 评论 复制链接分享

相关推荐