52 lines
1.7 KiB
Java
52 lines
1.7 KiB
Java
package com.bwie.rk;
|
||
|
||
import com.bwie.rk.pojo.Student;
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
import java.util.stream.Stream;
|
||
|
||
/**
|
||
* @Author:杨鹏
|
||
* @Package:com.bwie.rk
|
||
* @Project:yp_rikao88
|
||
* @name:TestApplication
|
||
* @Date:2024/8/8 8:39
|
||
*/
|
||
@SpringBootApplication
|
||
public class TestApplication {
|
||
|
||
public static void main(String[] args) {
|
||
|
||
List<String> list = new ArrayList<>();
|
||
|
||
// 1. 创建5名学生(Student)对象(编号,姓名,科目,分数)。(20分)
|
||
Student student1 = new Student(1, "韩立", "数学", "99");
|
||
Student student2 = new Student(2, "紫灵", "数学", "99");
|
||
Student student3 = new Student(3, "南宫婉", "数学", "99");
|
||
Student student4 = new Student(4, "历飞宇", "数学", "99");
|
||
Student student5 = new Student(5, "曲魂", "数学", "99");
|
||
|
||
// 2. 将所有学生拼接字符串放入集合中,如:1,张三,语文,100 2,张三,数学,90。(30分)
|
||
// 使用toString方法将对象拼接成字符串
|
||
String string1 = student1.toString();
|
||
String string2 = student2.toString();
|
||
String string3 = student3.toString();
|
||
String string4 = student4.toString();
|
||
String string5 = student5.toString();
|
||
// 将拼接好的对象放入到集合中
|
||
list.add(string1);
|
||
list.add(string2);
|
||
list.add(string3);
|
||
list.add(string4);
|
||
list.add(string5);
|
||
//3. 使用stream操作集合并输出每个人的名字及其平均成绩。(30分)
|
||
list.stream().forEach(lis ->{
|
||
System.out.println(lis);
|
||
});
|
||
|
||
}
|
||
|
||
}
|