使用JAVA实现一个班级学生成绩的管理功能:包括学生成绩的添加,学生成绩的删除,成绩的修改,学生成绩的查找(根据学号查找),以及按照学生平均成绩进行排名并显示。
由于当时学习的时候还不太会处理class和全局变量之类的,所以代码全挤在一个java文件里面了,所以足足有一千多行.……(接受批评但是不接受辱骂私密马赛
完整代码在本文最下面^^
public class Score_add {// 添加学生成绩窗口
Stage stage = new Stage();
public Score_add() {
//布局
BorderPane pane1 = new BorderPane();//总窗口
GridPane pane = new GridPane();//label和text field布局
HBox bt = new HBox(25);//放置按钮
HBox textBox = new HBox(25);//放置标题
//按钮
bt.setAlignment(Pos.CENTER);
bt.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
Button quedin = new Button("确定");
quedin.setStyle("-fx-base:lightblue");
quedin.setPrefSize(70, 50);
quedin.setFont(Font.font(20));
Button quxiao = new Button("取消");
quxiao.setStyle("-fx-base:lightblue");
quxiao.setPrefSize(70, 50);
quxiao.setFont(Font.font(20));
bt.getChildren().add(quedin);
bt.getChildren().add(quxiao);
//label和text field
//输入框
TextField name = new TextField();
TextField Sno = new TextField();
TextField math = new TextField();
TextField english = new TextField();
TextField java = new TextField();
TextField OS = new TextField();
TextField PE = new TextField();
//添加到面板中
pane.add(new Label("姓名:"), 0, 1);
pane.add(name, 1, 1);
pane.add(new Label("学号:"), 0, 2);
pane.add(Sno, 1, 2);
pane.add(new Label("高等数学成绩:"), 0, 3);
pane.add(math, 1, 3);
pane.add(new Label("大学英语成绩:"), 0, 4);
pane.add(english, 1, 4);
pane.add(new Label("java程序设计成绩:"), 0, 5);
pane.add(java, 1, 5);
pane.add(new Label("操作系统成绩:"), 0, 6);
pane.add(OS, 1, 6);
pane.add(new Label("体育成绩:"), 0, 7);
pane.add(PE, 1, 7);
pane.setAlignment(Pos.CENTER);
pane.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
pane.setHgap(5.5);
pane.setVgap(5.5);
pane.setStyle("-fx-font-size:20px");
//标题
Text add = new Text("添加学生成绩");
add.setStyle("-fx-font-size:30px");
textBox.setAlignment(Pos.CENTER);
textBox.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
textBox.getChildren().add(add);
//排列
pane1.setTop(textBox);
pane1.setCenter(pane);
pane1.setBottom(bt);
//创建一个新的学生类
student[peo] = new Student();
quedin.setOnAction(e -> {//点击确定
//将输入的内容复制到student[peo]信息中
student[peo].name=name.getText();
student[peo].Sno=Sno.getText();
student[peo].math=Double.valueOf(math.getText());
student[peo].english=Double.valueOf(english.getText());
student[peo].java=Double.valueOf(java.getText());
student[peo].OS=Double.valueOf(OS.getText());
student[peo].PE=Double.valueOf(PE.getText());
//计算平均分
sum =0.0;
if(student[peo].math>=0)
sum+=student[peo].math;
if(student[peo].english>=0)
sum+=student[peo].english;
if(student[peo].java>=0)
sum+=student[peo].java;
if(student[peo].OS>=0)
sum+=student[peo].OS;
if(student[peo].PE>=0)
sum+=student[peo].PE;
student[peo].GPA = sum/5;
flag1=0;flag2=0;//flag1=1表示学号重复,flag2=1表示输入的成绩有误
//学号查重
for (d = 0; d <peo; d++) {
if (student[d].name.equals(name.getText())) {
TipsWin tip = new TipsWin("该学号已存在!");
flag1=1;
break;
}
}
if (flag1==0) {
//判断输入的成绩是否有误
if (student[peo].math<0.0||student[peo].math>100.00||student[peo].english<0.0||student[peo].english>100.00||
student[peo].java<0.0||student[peo].java>100.00||student[peo].OS<0.0||student[peo].OS>100.00||
student[peo].PE<0.0||student[peo].PE>100.00) {
TipsWin tipsWin = new TipsWin("输入有误\n 请重新输入!");
flag2=1;//表示有误
}
if (flag2==0) {
if(student[peo].name.length()==4) {
text.appendText(padLeft(student[peo].name,14,' '));
}
if(student[peo].name.length()==3) {
text.appendText(padLeft(student[peo].name,16,' '));
}
if(student[peo].name.length()==2) {
text.appendText(padLeft(student[peo].name,18,' '));
}
text.appendText(padLeft(student[peo].Sno,15,' '));
text.appendText(padLeft(String.valueOf(student[peo].math),15,' '));
text.appendText(padLeft(String.valueOf(student[peo].english),15,' '));
text.appendText(padLeft(String.valueOf(student[peo].java),15,' '));
text.appendText(padLeft(String.valueOf(student[peo].OS),15,' '));
text.appendText(padLeft(String.valueOf(student[peo].PE),15,' '));
text.appendText(padLeft(String.valueOf(student[peo].GPA),15,' ')+"\n");
peo++;//学生数+1
//输入完成后写入文件保存
write();
stage.close();
TipsWin tipsWin = new TipsWin("添加成功!");
}
}
});
quxiao.setOnAction(e -> {
stage.close();
});
Scene scene = new Scene(pane1, 600, 550);
stage.setTitle("添加学生成绩"); // Set the stage title
stage.setScene(scene); // Place the scene in the stage
stage.show(); // Display the stage
}
}
public class findFormation {// 查找学生成绩总窗口
Stage stage = new Stage();
int index=-1;
public findFormation() {
//布局
BorderPane pane1 = new BorderPane();//总窗口
GridPane pane = new GridPane();//label和text field布局
HBox bt = new HBox(25);//放置按钮
HBox textBox = new HBox(25);//放置标题
//按钮
bt.setAlignment(Pos.CENTER);
bt.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
Button quedin = new Button("确定");
quedin.setStyle("-fx-base:lightblue");
quedin.setPrefSize(70, 50);
quedin.setFont(Font.font(20));
Button quxiao = new Button("取消");
quxiao.setStyle("-fx-base:lightblue");
quxiao.setPrefSize(70, 50);
quxiao.setFont(Font.font(20));
bt.getChildren().add(quedin);
bt.getChildren().add(quxiao);
//label和text field
//输入框
TextField Sno = new TextField();
//添加到面板中
pane.add(new Label("学号:"), 0, 1);
pane.add(Sno, 1, 1);
pane.setAlignment(Pos.CENTER);
pane.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
pane.setHgap(5.5);
pane.setVgap(5.5);
pane.setStyle("-fx-font-size:20px");
//标题
Text del = new Text("查找学生成绩");
del.setStyle("-fx-font-size:30px");
textBox.setAlignment(Pos.CENTER);
textBox.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
textBox.getChildren().add(del);
//排列
pane1.setTop(textBox);
pane1.setCenter(pane);
pane1.setBottom(bt);
quedin.setOnAction(e -> {//点击确定
for(int i=0; i<peo; i++) {
if(student[i].Sno.equals(Sno.getText())) {
index=i;
Show show = new Show(index);
stage.close();
}
}
if(index == -1) {
TipsWin tipsWin = new TipsWin("查无此学生信息!\n 请重新输入");
}
});
quxiao.setOnAction(e -> {
stage.close();
});
Scene scene = new Scene(pane1, 500, 300);
stage.setTitle("查找学生成绩"); // Set the stage title
stage.setScene(scene); // Place the scene in the stage
stage.show(); // Display the stage
}
}
public class Show{//查找后显示操作窗口
Stage stage=new Stage();
public Show(int index) {
BorderPane pane = new BorderPane();//总窗口
VBox bt = new VBox(25);//放置文本
bt.setAlignment(Pos.CENTER);
bt.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
pane.setStyle("-fx-font-size:20px");
//标题
Text cho = new Text("学生成绩");
cho.setStyle("-fx-font-size:30px");
bt.getChildren().add(cho);
//文本
Text nameText = new Text("姓名:"+student[index].name);
Text snoText = new Text("学号:"+student[index].Sno);
Text mathText = new Text("高等数学:"+String.valueOf(student[index].math));
Text englishText = new Text("大学英语:"+String.valueOf(student[index].english));
Text JavaText = new Text("java程序设计:"+String.valueOf(student[index].java));
Text OSText = new Text("操作系统:"+String.valueOf(student[index].OS));
Text PEText = new Text("体育:"+String.valueOf(student[index].PE));
Text GPAText = new Text("平均分:"+String.valueOf(student[index].GPA));
bt.getChildren().addAll(nameText,snoText,mathText,englishText,JavaText,OSText,PEText,GPAText);
//按钮
Button quxiao = new Button("关闭");
quxiao.setPrefSize(100, 40);
quxiao.setFont(Font.font(20));
bt.getChildren().add(quxiao);
//排列
pane.setCenter(bt);
//按钮触发事件
quxiao.setOnAction(e->{
stage.close();
});
Scene scene = new Scene(pane, 500, 600);
stage.setTitle("查找学生成绩"); // Set the stage title
stage.setScene(scene); // Place the scene in the stage
stage.show(); // Display the stage
}
}
其他的就不展示啦~实在是太多了,是本人大二时与两个组员一起完成的作业,总之有很多不足的地方,欢迎大家一起交流讨论鸭。
这是完整代码链接↓(不收钱哒!大家如果下载的话点个赞就好啦谢谢大噶~
https://download.csdn.net/download/nabobess/70249599