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

  • 相关阅读:
    Hook钩子程序
    KMeans笔记 K值以及初始类簇中心点的选取
    自己用C#写的一个俄罗斯方块的小程序(附源代码)。
    那些帮助你成为优秀前端工程师的讲座——《JavaScript篇》
    Mac技巧合集第二期
    WCF增加UDP绑定(应用篇)
    第一个MVC4 Web应用程序
    jQuery的页面加载事件
    通过网页进行 iOS 应用内部分发
    sql count效率
  • 原文地址:https://www.cnblogs.com/yuyang-gr/p/6759024.html
Copyright © 2011-2022 走看看