Java源代码,开发一个简易信息管理软件,要求需求定义清晰,源代码符合规范,设计良好的图形用户界面,方便用户的操作。示例,班级成绩管理系统,管理一个班30人的思政、高数、英语、体育四科的成绩,主要功能有:学生信息管理,各门课成绩管理,成绩统计与排序等。 模式:包含需求分析、详细设计、编码、测试等内容。 知识点:涵盖基本程序设计、面向对象程序设计、GUI 程序设计(课外自学JavaFXTableView)
时间: 2024-03-23 11:42:13 浏览: 24
好的,这是一个比较详细和复杂的项目,需要充分考虑需求和设计,以下是一个示例的Java源代码,供你参考:
```java
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class StudentManagementSystem extends Application {
private ObservableList<Student> studentList = FXCollections.observableArrayList();
private TableView<Student> studentTable = new TableView<>();
private TextField idField = new TextField();
private TextField nameField = new TextField();
private TextField mathField = new TextField();
private TextField englishField = new TextField();
private TextField peField = new TextField();
private Label idLabel = new Label("学号:");
private Label nameLabel = new Label("姓名:");
private Label mathLabel = new Label("数学:");
private Label englishLabel = new Label("英语:");
private Label peLabel = new Label("体育:");
@Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
root.setPadding(new Insets(10, 10, 10, 10));
// 添加学生信息
GridPane addPane = new GridPane();
addPane.setHgap(10);
addPane.setVgap(10);
addPane.addRow(0, idLabel, idField);
addPane.addRow(1, nameLabel, nameField);
addPane.addRow(2, mathLabel, mathField);
addPane.addRow(3, englishLabel, englishField);
addPane.addRow(4, peLabel, peField);
Button addButton = new Button("添加");
addButton.setOnAction(event -> addStudent());
addPane.addRow(5, addButton);
root.setLeft(addPane);
// 展示学生信息
TableColumn<Student, String> idColumn = new TableColumn<>("学号");
idColumn.setCellValueFactory(cellData -> cellData.getValue().getId());
TableColumn<Student, String> nameColumn = new TableColumn<>("姓名");
nameColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
TableColumn<Student, String> mathColumn = new TableColumn<>("数学");
mathColumn.setCellValueFactory(cellData -> cellData.getValue().getMath());
TableColumn<Student, String> englishColumn = new TableColumn<>("英语");
englishColumn.setCellValueFactory(cellData -> cellData.getValue().getEnglish());
TableColumn<Student, String> peColumn = new TableColumn<>("体育");
peColumn.setCellValueFactory(cellData -> cellData.getValue().getPe());
studentTable.getColumns().addAll(idColumn, nameColumn, mathColumn, englishColumn, peColumn);
root.setCenter(studentTable);
// 统计学生信息
GridPane statisticPane = new GridPane();
statisticPane.setHgap(10);
statisticPane.setVgap(10);
Label averageLabel = new Label("平均分:");
TextField averageField = new TextField();
averageField.setEditable(false);
statisticPane.addRow(0, averageLabel, averageField);
Label maxLabel = new Label("最高分:");
TextField maxField = new TextField();
maxField.setEditable(false);
statisticPane.addRow(1, maxLabel, maxField);
Label minLabel = new Label("最低分:");
TextField minField = new TextField();
minField.setEditable(false);
statisticPane.addRow(2, minLabel, minField);
Button statisticButton = new Button("统计");
statisticButton.setOnAction(event -> {
double average = 0;
double max = 0;
double min = 100;
for (Student student : studentList) {
double sum = student.getMathScore() + student.getEnglishScore() + student.getPeScore();
average += sum;
max = Math.max(max, sum);
min = Math.min(min, sum);
}
average /= studentList.size();
averageField.setText(String.format("%.2f", average));
maxField.setText(String.format("%.2f", max));
minField.setText(String.format("%.2f", min));
});
statisticPane.addRow(3, statisticButton);
root.setBottom(statisticPane);
Scene scene = new Scene(root, 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
private void addStudent() {
String id = idField.getText();
String name = nameField.getText();
String math = mathField.getText();
String english = englishField.getText();
String pe = peField.getText();
if (id == null || id.isEmpty() || name == null || name.isEmpty() || math == null || math.isEmpty() || english == null || english.isEmpty() || pe == null || pe.isEmpty()) {
return;
}
Student student = new Student(id, name, Double.parseDouble(math), Double.parseDouble(english), Double.parseDouble(pe));
studentList.add(student);
idField.clear();
nameField.clear();
mathField.clear();
englishField.clear();
peField.clear();
}
public static void main(String[] args) {
launch(args);
}
private static class Student {
private SimpleStringProperty id;
private SimpleStringProperty name;
private SimpleStringProperty math;
private SimpleStringProperty english;
private SimpleStringProperty pe;
public Student(String id, String name, double math, double english, double pe) {
this.id = new SimpleStringProperty(id);
this.name = new SimpleStringProperty(name);
this.math = new SimpleStringProperty(String.format("%.2f", math));
this.english = new SimpleStringProperty(String.format("%.2f", english));
this.pe = new SimpleStringProperty(String.format("%.2f", pe));
}
public SimpleStringProperty getId() {
return id;
}
public SimpleStringProperty getName() {
return name;
}
public SimpleStringProperty getMath() {
return math;
}
public SimpleStringProperty getEnglish() {
return english;
}
public SimpleStringProperty getPe() {
return pe;
}
public double getMathScore() {
return Double.parseDouble(math.get());
}
public double getEnglishScore() {
return Double.parseDouble(english.get());
}
public double getPeScore() {
return Double.parseDouble(pe.get());
}
}
}
```
这个示例程序使用JavaFX来实现图形用户界面,主要分为三个部分:添加学生信息、展示学生信息和统计学生信息。其中,学生信息保存在一个`ObservableList`中,展示使用`TableView`来呈现,并且可以进行排序。统计功能包括计算平均分、最高分和最低分。这个示例程序可能还有一些不完善的地方,可以根据实际情况进行调整和修改。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![iso](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)