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

      }

    运行结果:

  • 相关阅读:
    [CF1295E] Permutation Separation
    [APIO2010] 特别行动队
    [CF1296F] Berland Beauty
    [CEOI2004] 锯木厂选址
    [CF1334E] Divisor Paths
    Review 2020.11.14
    [CQOI2016] 手机号码
    [LEETCODE600] 不含连续1的非负整数
    [CF55D] Beautiful numbers
    内存取证工具volatility
  • 原文地址:https://www.cnblogs.com/duanqibo/p/11133278.html
Copyright © 2011-2022 走看看