zoukankan      html  css  js  c++  java
  • classNum 表示学生的班号,例如“class05”。 有如下List  List list = new ArrayList();

    package a927;
    
    import java.util.ArrayList;
    import java.util.List;
    
    class Student
    {
        private String name ;
        private int age ;
        private int score ;
        private String classNum ;
        
        public Student(String name, int age, int score , String classNum )
        {
            this.age= age ;
            this.classNum = classNum ;
            this.name = name ;
            this.score = score ;
        }
    
        public int getAge() {
            return age;
        }
    
        public void setAge(int age) {
            this.age = age;
        }
    
        public int getScore() {
            return score;
        }
    
        public void setScore(int score) {
            this.score = score;
        }
    
        public String getClassNum() {
            return classNum;
        }
    
        public void setClassNum(String classNum) {
            this.classNum = classNum;
        }
        
    }
    
    
    
    
    public class A {
    
        public static void main(String[] args) 
        {
            List<Student> list = new ArrayList<>() ;
            
            list.add(new Student("Tom", 18 ,100 , "class05" )) ;
            list.add(new Student("jerry", 22 ,70 , "class04" )) ;
            list.add(new Student("Owen", 25 ,90 , "class05" )) ;
            list.add(new Student("Jim", 30 ,80 , "class05" )) ;
            list.add(new Student("Steve", 28 ,66 , "class06" )) ;
            list.add(new Student("Kevin", 24 ,100 , "class04" )) ;
            
            double  sum = 0 ;
            
            for(int i = 0 ; i<list.size();i++)
            {
                sum += list.get(i).getAge();
            }
    
            System.out.println("平均年龄为:" + sum/list.size());
            int sum4 = 0 ;
            int j4 = 0 ;
            int sum5 = 0 ;
            int j5 = 0 ;
            int sum6 = 0 ;
            int j6 = 0 ;
            for(Student x  : list)
            {
                if(x.getClassNum().equals("class05") )
                {
                    sum5 +=x.getScore( ) ;    
                    ++ j5  ;
                }
                if(x.getClassNum().equals("class04") )
                {
                    sum4 +=x.getScore( ) ;    
                    ++ j4  ;
                }
                if(x.getClassNum().equals("class06") )
                {
                    sum6 +=x.getScore( ) ;    
                    ++ j6  ;
                }
            }
            System.out.println("class05的平均成绩:"+sum5/j5);
            System.out.println("class04的平均成绩:"+sum4/j4);
            System.out.println("class06的平均成绩:"+sum6/j6);
        }
    
    }

  • 相关阅读:
    POJ 3694 Network (求桥,边双连通分支缩点,lca)
    UVA 796
    UVA 315 315
    POJ 1236 Network of Schools (有向图的强连通分量)
    【转】有向图强连通分量的Tarjan算法
    HDU 3072 Intelligence System (强连通分量)
    【转】强大的vim配置文件,让编程更随意
    WORDPRESS登录后台半天都无法访问或者是访问慢的解决方法
    phpstorm+Xdebug断点调试PHP
    PHP性能调优---PHP调试工具Xdebug安装配置教程
  • 原文地址:https://www.cnblogs.com/20gg-com/p/5913309.html
Copyright © 2011-2022 走看看