码迷,mamicode.com
首页 > 其他好文 > 详细

0926-----homework(3)

时间:2016-09-28 13:08:11      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 1 /**
 2   *homework0926
 3   *@author:kai li
 4   */
 5 package com.kai.li.homework0926;
 6 import java.util.List;
 7 import java.util.ArrayList;
 8 import java.util.Arrays;
 9 
10 /**
11   *following class is client 
12   */
13 public class HomeWork0926{
14     public static void main(String[] args)throws Exception{
15         
16         /**
17           *question three
18           */
19 
20         /*create data source*/
21 
22     List<Student> students=Arrays.asList(new Student("小明",18,100,"class05"),new Student("小黄",22,70,"class06"),new Student("小真",25,90,"class07"),new Student("小花",30,80,"class08"),new Student("tom",28,66,"class05"),new Student("jerry",24,100,"class04")); 
23     
24     /*operate*/
25     int sumAge=students.stream().mapToInt(Student::getAge).sum();
26     int sumScore=students.stream().mapToInt(Student::getScore).sum();
27     System.out.println("学生的平均年龄是:"+sumAge/students.size()+",平均分数是:"+sumScore/students.size());
28     }
29 }
30 /**
31   *following class for question three
32   *create data source class
33   *student class
34   */
35 class Student{
36     private String name;
37     private int age;
38     private int score;
39     private String classNum;
40     Student(String name,int age,int score,String classNum){
41         this.name=name;
42         this.age=age;
43         this.score=score;
44         this.classNum=classNum;
45     }
46     public String getName(){
47         return name;
48     }
49     public int getAge(){
50         return age;
51     }
52     public int getScore(){
53         return score;
54     }
55     public String getClassNum(){
56         return classNum;
57     }
58 }

 

0926-----homework(3)

标签:

原文地址:http://www.cnblogs.com/kaililikai/p/5915612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!