zoukankan      html  css  js  c++  java
  • 求总分、平均分--简单

     

    import java.text.DecimalFormat;

    class student   //学生类

    {

      String stuNo;

      String stuName;

      String stuSex;

      boolean banganbu;

      double math;

      double chinese;

      double english; 

      void input(String sNo,String sName,String sex,boolean bgb,double math1,double chinese1,double english1)  //input成员函数

      {    // 类的成员函数接收实际参数,给类的数据成员赋值

        stuNo=sNo;

        stuName=sName;

        stuSex=sex;

        banganbu=bgb;

        math=math1;

        chinese=chinese1;

        english=english1;

      }

      double sum_score()

      {

        double sum;

        sum=math+chinese+english;

        return sum;

      }

      double avg()

      {

        double average;

        average=sum_score()/3;

        return average;

      }

    }

    public class p94_13 {

      public static void main(String []args)

      {

        student stu=new student();   //用类student创建对象stu

        //Scanner reader=new Scanner(System.in);

        stu.input("1001","zhangsan","m",true,85.5,90,88);  //直接赋值(只是一个学生的情况)

        double sum=stu.sum_score();  //用对象调用类的成员函数sum_score()

        double avg=stu.avg();   //用对象调用成员函数avg()

        DecimalFormat df = new DecimalFormat("#.0");  //平均分保留一位小数

        System.out.println("总分:"+sum + "     平均分:"+df.format(avg));

      }

    运行结果:

  • 相关阅读:
    Mybatisplus<一> Springboot框架使用MybatisPlus代码自动生成器
    今日收获
    今日收获
    字典特征提取
    sklearn数据集的导入及划分
    文本特征提取
    MySQL基础笔记
    docker笔记
    BOM 中的location对象和history对象
    完善 原生Js 实现的简单无缝滚动轮播图
  • 原文地址:https://www.cnblogs.com/duanqibo/p/11133278.html
Copyright © 2011-2022 走看看