程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> java-有一個關於Java的小題目,做了好久做不出來,還請大神幫我

java-有一個關於Java的小題目,做了好久做不出來,還請大神幫我

編輯:編程解疑
有一個關於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
                + "]";
    }



}

最佳回答:


圖片說明

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved