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);
        }
    }
  • 相关阅读:
    git常用操作命令
    如何编写高质量代码
    Chrome调试工具简单介绍
    使用eclipse+tomcat搭建本地环境
    chrome设置--disable-web-security解决跨域
    利用Maven管理工程项目本地启动报错及解决方案
    用户输入验证【提升篇】
    简单【用户输入验证】
    【消息框】的返回值
    【消息框】的4种显示形式
  • 原文地址:https://www.cnblogs.com/yuanyuan2017/p/6561047.html
Copyright © 2011-2022 走看看