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));

      }

    运行结果:

  • 相关阅读:
    JavaScript的正则表达式的基础
    运用JS判断代码可以参考学习
    调用百度地图代码
    运用了css,js
    中国地图(Highmaps)
    Centos
    代理模式【 动态代理与静态代理】
    java集合 collection-list-LinkedList 模拟一个堆栈或者队列数据结构。
    java集合 collection-list-LinkedList
    java集合 collection-list-vector
  • 原文地址:https://www.cnblogs.com/duanqibo/p/11133278.html
Copyright © 2011-2022 走看看