JAVA 简易学生成绩管理系统
·
简易学生成绩管理系统
功能描述:通过控制台输入学生信息(姓名、学号、成绩),支持添加、查询、删除和统计平均分。
核心代码:
import java.util.ArrayList;
import java.util.Scanner;
class Student {
String name;
String id;
double score;
public Student(String name, String id, double score) {
this.name = name;
this.id = id;
this.score = score;
}
}
public class ScoreManager {
static ArrayList<Student> students = new ArrayList<>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("1.添加 2.查询 3.删除 4.平均分 5.退出");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("姓名 学号 成绩:");
students.add(new Student(scanner.next(), scanner.next(), scanner.nextDouble()));
break;
case 2:
students.forEach(s -> System.out.println(s.name + " " + s.score));
break;
case 3:
System.out.print("输入学号:");
String id = scanner.next();
students.removeIf(s -> s.id.equals(id));
break;
case 4:
double avg = students.stream().mapToDouble(s -> s.score).average().orElse(0);
System.out.println("平均分:" + avg);
break;
case 5:
System.exit(0);
}
}
}
}
以上案例涵盖基础语法、多线程和框架应用,适合不同阶段的Java开发者参考。
更多推荐


所有评论(0)