zoukankan      html  css  js  c++  java
  • 成绩

    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

  • 相关阅读:
    MongoDB数据库性能分析(转)
    C++中拷贝构造函数
    C++中的继承和组合区别使用
    几种调用约定
    动态规划(基础篇)
    C++中的三种继承public,protected,private
    STl中的排序算法
    STL中的常用算法
    C++初始化函数列表
    设计模式之装饰模式(Decorator)
  • 原文地址:https://www.cnblogs.com/lx-20163311114/p/9101948.html
Copyright © 2011-2022 走看看