zoukankan      html  css  js  c++  java
  • 简单的综合的写了一个demo

    package cn.xuexi;
    /*
     * 作业:
     * 定义一个测试类为student,属性有“学号”,“姓名”,“数学成绩”,英语成绩,计算机成绩,其中包括的方法有总分,平均分,最高分,最低分
     * 分析思路:
     * 1、写出类中包含的属性
     * 2、所有的属性都必须封装,并通过setter getter调用
     * 3、添加成员方法计算总成绩,平均分,最高分,最低分
     * 4、写一个构造函数为类中属性赋值 
     */
    public class ZongHeDemo {
    public static void main(String[] args) {
        student s = new student("fhuehf","2011x",89.9f,35.5f,43.6f);
        System.out.println(s.getid()+"****"+s.getname()+"****"+s.avg()+"****"+s.max()+"****"+s.min());
    }
    }
    class student{
        //申明类中属性
        private String name;
        private  String id;
        private float  math;
        private float english;
        private float computer;
        public void setname(String name)
        {
            this.name = name;
        }
        public void setid(String id)
        {
            this.id = id;
        }
        public void setmath(float math)
        {
            this.math = math;
        }
        public void setenglish(float english)
        {
            this.english = english;
        }
        public void setcomputer(float computer)
        {
            this.computer = computer;
        }
        public String getname()
        {
            return name;
        }
        public String getid()
        {
            return id;
        }
        public float getmath()
        {
            return math;
        }
        public float getenglish()
        {
            return english;
        }
        public float getcomputer()
        {
            return computer;
        }
        public float sum()
        {
            float sum;
            sum = (this.getmath()+this.getcomputer()+this.getenglish());
            return sum;
        }
        public float avg()
        {
            float av;
            av = (this.getmath()+this.getcomputer()+this.getenglish())/3;
            return av;
        }    
        public float max()
        {
            float max;
            if (math>english){
                max = math;
            }
                else {
                    max = english;
                }
            
                if (computer>max) {
                    max = computer ;
                    return max;
                }
                else {
                    return max;
                }
            }
        
        public float min()
        {float min;
        if (math>english){
            min = english;
        }
            else {
                min = math;
            }
        
            if (computer>min) {
                
                return min;
            }
            else {
                min = computer ;
                return min;
            }
        }
        //写一个构造方法,为类中属性初始化
        public student(String name,String id,float math,float english,float computer)
        {
            this.setcomputer(computer);
            this.setenglish(english);
            this.setmath(math);
            this.setname(name);
            this.setid(id);
        }
    }
  • 相关阅读:
    idea执行报错NoClassDefFoundError
    git合并几个commit
    jenkins+allure+持续构建+一些配置和遇到的问题
    接口框架坑记录
    jvm-sandbox对运行中的java执行文件做插桩,故障注入
    linux 安装nogui-chrome,构造selenium运行环境
    python之pychram激活码
    python之闭包、装饰器、生成器、反射
    python之 Requests入门到实践
    Python使用xlwt模块 操作Excel文件(转载)
  • 原文地址:https://www.cnblogs.com/yuanyuan2017/p/6561047.html
Copyright © 2011-2022 走看看