用java编写一个学生成绩管理系统 ,主要功能: 1、从记事本读取一个班级的学生的基本信息(包括学号,姓名,性别,5门课程成绩)。
时间: 2023-09-14 19:09:15 浏览: 107
线性表的链式表示和实现(学生成绩管理系统).doc )
好的,我可以为您提供一个Java代码示例,实现学生成绩管理系统的基本功能。首先需要明确的是,需要使用文件输入/输出功能来实现从记事本读取学生信息的功能。以下是示例代码:
```java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class StudentScoreManagementSystem {
private static final String FILE_PATH = "students.txt"; // 学生信息文件路径
private static List<Student> students = new ArrayList<>(); // 学生列表
public static void main(String[] args) {
readStudentsFromFile(); // 从文件读取学生信息
printAllStudents(); // 打印所有学生信息
}
// 从文件读取学生信息
private static void readStudentsFromFile() {
try {
Scanner scanner = new Scanner(new File(FILE_PATH));
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] fields = line.split(",");
String id = fields[0];
String name = fields[1];
String gender = fields[2];
int mathScore = Integer.parseInt(fields[3]);
int englishScore = Integer.parseInt(fields[4]);
int chineseScore = Integer.parseInt(fields[5]);
Student student = new Student(id, name, gender, mathScore, englishScore, chineseScore);
students.add(student);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
// 打印所有学生信息
private static void printAllStudents() {
System.out.println("学号\t姓名\t性别\t数学\t英语\t语文\t总分\t平均分");
for (Student student : students) {
System.out.println(student.getId() + "\t" + student.getName() + "\t" + student.getGender() + "\t" +
student.getMathScore() + "\t" + student.getEnglishScore() + "\t" + student.getChineseScore() +
"\t" + student.getTotalScore() + "\t" + student.getAverageScore());
}
}
}
class Student {
private String id; // 学号
private String name; // 姓名
private String gender; // 性别
private int mathScore; // 数学成绩
private int englishScore; // 英语成绩
private int chineseScore; // 语文成绩
public Student(String id, String name, String gender, int mathScore, int englishScore, int chineseScore) {
this.id = id;
this.name = name;
this.gender = gender;
this.mathScore = mathScore;
this.englishScore = englishScore;
this.chineseScore = chineseScore;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public int getMathScore() {
return mathScore;
}
public int getEnglishScore() {
return englishScore;
}
public int getChineseScore() {
return chineseScore;
}
public int getTotalScore() {
return mathScore + englishScore + chineseScore;
}
public double getAverageScore() {
return getTotalScore() / 3.0;
}
}
```
以上代码实现了从文件读取学生信息并打印出来的功能。您可以根据需要进行修改,例如添加学生信息的输入功能、根据学生ID或姓名查询学生信息的功能等。
阅读全文