成绩

package 成绩;

public class Grade {
    private

    double biology;
     double math;
     double english;
     
    public Grade(double b, double m, double e)
    {
       b= biology;
        m= math;
        e = english;
    }
 
    public double total() {
        return biology + math + english;
    }
     
    public void printTotal() {
        System.out.println(total());
    }
     
    public double average() {
        return total() / 3;
    }
     
    public void printAverage() {
        System.out.println(average());
    }
    public double getbiology() {
        return biology;
    }
 
    public void setbiology(double biology) {
        this.biology = biology;
    }
 
    public double getMath() {
        return math;
    }
 
    public void setMath(double math) {
        this.math = math;
    }
 
    public double getenglish() {
        return english;
    }
 
    public void setenglish(double english) {
        this.english = english;
    }
}

 class Student {
    String name;
    Grade grade;
    public Student(String name, Grade grade) {
        this.name = name;
        this.grade = grade;
    }
     
    public static void main(String[] args) {
        Student s = new Student("Cici", new Grade(100, 94, 90));
        s.grade.printAverage();
        s.grade.printTotal();
    }
}
结果:

94.66666
284.0

posted on 2018-05-28 19:52  '大大'  阅读(113)  评论(0编辑  收藏  举报