初始化
commit
4e3c5635aa
|
@ -0,0 +1,38 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.icecream</groupId>
|
||||
<artifactId>zgl-rikao-day19-8-8</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,74 @@
|
|||
package com.muyu.pojo;
|
||||
|
||||
|
||||
|
||||
|
||||
public class Student {
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private int id;
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 科目
|
||||
*/
|
||||
private String subject;
|
||||
/**
|
||||
* 分数
|
||||
*/
|
||||
private int score;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return
|
||||
"编号:" + id +
|
||||
"姓名:" + name +
|
||||
"科目:" + subject +
|
||||
"分数" + score ;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(int score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public Student() {
|
||||
}
|
||||
|
||||
public Student(int id, String name, String subject, int score) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.subject = subject;
|
||||
this.score = score;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.muyu.test;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class StudentTest {
|
||||
public static void main(String[] args) {
|
||||
List<String> studentInfoStrings = new ArrayList<>();
|
||||
//创建并添加学生信息到集合
|
||||
studentInfoStrings.add("1,张三,语文,100");
|
||||
studentInfoStrings.add("1,张三,数学,90");
|
||||
studentInfoStrings.add("2,李四,语文,95");
|
||||
studentInfoStrings.add("2,李四,数学,92");
|
||||
studentInfoStrings.add("3,王五,语文,88");
|
||||
studentInfoStrings.add("3,王五,数学,82");
|
||||
|
||||
// 打印集合
|
||||
studentInfoStrings.forEach(System.out::println);
|
||||
|
||||
System.out.println("----------------------添加数据之后-----------------------");
|
||||
|
||||
Map<String, Double> averageScores = studentInfoStrings.stream()
|
||||
.map(s -> s.split(","))
|
||||
.collect(Collectors.groupingBy(
|
||||
arr -> arr[1], // 假设arr[1]是名字
|
||||
Collectors.mapping(
|
||||
arr -> Integer.parseInt(arr[3]), // 假设arr[3]是分数
|
||||
Collectors.averagingInt(i -> i)
|
||||
)
|
||||
));
|
||||
|
||||
// 输出平均成绩结果
|
||||
averageScores.forEach((name, avgScore) -> System.out.println(name + "的平均成绩是: " + avgScore));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue