zoukankan      html  css  js  c++  java
  • Java程序设计基础 面向对象 练习

      最近JAVA开了面向对象的课程,老师布置了作业,嗯,就是这样,啥作业我不怎么会描述,代码如下,自己做的,代码很不成熟,请谅解!大概就是这样:

    class Student
    {
        private String stuno;
        private String name;
        private float math;
        private float english;
        private float computer;
        
        /*Student()
        {
    
        }*/
        public void StuPer(String stuno,String name)
        {
            this.stuno = stuno;
            this.name = name;
        }
        public void stuGrade(float math,float english,float computer)
        {
            this.math = math;
            this.english = english;
            this.computer = computer;
        }
        public void count()
        {
            float average = (math + english + computer)/3;
            System.out.println("平均成绩为:" + average);
            float sum = (math + english + computer);
            System.out.println("总成绩为:" + sum);
            float max = 0;
            if(math > english)
            {
                max = math;
            }
            else 
            {
                max = english;
            }
            if(max > computer)
            {
                System.out.println("最高成绩为:" + max);
            }
            else
            {
                System.out.println("最高成绩为:" + computer);
            }
            float min = 0;
             if(math > english)
            {
                min = english;
            }
            else 
            {
                min = math;
            }
            if(min > computer)
            {
                System.out.println("最低成绩为:" + computer);
            }
            else
            {
                System.out.println("最低成绩为:" + min);
            }
        }
        public void tell()
        {
            System.out.println("姓名:" + name + "  学号: " + stuno);
            System.out.println("数学成绩: " + math + "英语成绩: " + english + "计算机成绩: " + computer);
        }
    }
    class stuInfo
    {
        public static void main(String[] args)
        {
            Student person = new Student();
            person.StuPer("2015025500","张三");
            person.stuGrade(50,60,70);
            person.tell();
            person.count();
        } 
    }

      程序运行结果为:

      姓名:张三 学号: 2015025500
      数学成绩: 50.0英语成绩: 60.0计算机成绩: 70.0
      平均成绩为:60.0
      总成绩为:180.0
      最高成绩为:70.0
      最低成绩为:50.0

  • 相关阅读:
    mongodb的账户管理
    mongo备份与恢复
    mongo索引
    聚合aggregate
    07-【jsp基本了解】
    Servlet登录小案例
    06-【servletconfig、servletContext 】
    05-【session、cookie】
    jQuery
    04-【servlet转发和重定向】
  • 原文地址:https://www.cnblogs.com/yuyang-gr/p/6759024.html
Copyright © 2011-2022 走看看