|
|
|
@ -0,0 +1,204 @@
|
|
|
|
|
package edu.course_text;
|
|
|
|
|
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
public class System_stu {
|
|
|
|
|
private static final int MaxNum=100;
|
|
|
|
|
private static Score[] scoreStudent=new Score[MaxNum];
|
|
|
|
|
private static int numStudent=0;
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
Scanner sc=new Scanner(System.in);
|
|
|
|
|
System.out.println("*************************");
|
|
|
|
|
System.out.println("***欢迎使用学生成绩管理系统***");
|
|
|
|
|
System.out.println("*************************");
|
|
|
|
|
ABC: while(true){
|
|
|
|
|
System.out.println("以下是菜单栏");
|
|
|
|
|
System.out.println("1-查看、2-添加");
|
|
|
|
|
System.out.println("3-修改、4-删除");
|
|
|
|
|
System.out.println("5-统计、6-查找");
|
|
|
|
|
System.out.println("7-排序、0-退出");
|
|
|
|
|
System.out.println("请输入你的选项:");
|
|
|
|
|
String choose=sc.next();
|
|
|
|
|
switch (choose){
|
|
|
|
|
case "1" : displayScore();break;
|
|
|
|
|
case "2" : AddScore(sc);break;
|
|
|
|
|
case "3" : updateScore(sc);break;
|
|
|
|
|
case "4" : deleteScore(sc);break;
|
|
|
|
|
case "5" : sumScore(sc);break;
|
|
|
|
|
case "6" : searchScore(sc);break;
|
|
|
|
|
case "7" : sortScore(sc);break;
|
|
|
|
|
case "0" : System.out.println("退出成功!");break ABC;
|
|
|
|
|
default :System.out.println("没有此选项");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static void displayScore(){//查询
|
|
|
|
|
if(numStudent==0){
|
|
|
|
|
System.out.println("尚未添加学生,请返回菜单首页添加");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
System.out.println("下面为您展示学生成绩单");
|
|
|
|
|
System.out.println("序号\t\t学生姓名\t学生学号\t课程名称\t课程成绩");
|
|
|
|
|
for(int i=0;i<numStudent;i++){
|
|
|
|
|
Score s=scoreStudent[i];
|
|
|
|
|
System.out.print(s.id);
|
|
|
|
|
System.out.print(s.stuName);
|
|
|
|
|
System.out.print(s.stu_id);
|
|
|
|
|
System.out.print(s.scoreName);
|
|
|
|
|
System.out.print(s.score);
|
|
|
|
|
System.out.println();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static void AddScore(Scanner scanner){//增加
|
|
|
|
|
System.out.println("请输入添加的人数");
|
|
|
|
|
int temp=scanner.nextInt();
|
|
|
|
|
int j=numStudent;
|
|
|
|
|
for(int i=j;i<j+temp;i++){
|
|
|
|
|
//先创建具体数组的对象
|
|
|
|
|
scoreStudent[i]=new Score();
|
|
|
|
|
while(true){
|
|
|
|
|
System.out.println("输入学号");
|
|
|
|
|
String stu_id=scanner.next();
|
|
|
|
|
boolean flag=contains(stu_id);
|
|
|
|
|
if(flag){
|
|
|
|
|
System.out.println("学号重复,请重新输入");
|
|
|
|
|
//bug多组输入出问题,bug解决原因是循环内num没有改变
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
scoreStudent[i].stu_id=stu_id;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println("请输入该学生的序号");
|
|
|
|
|
int id=scanner.nextInt();
|
|
|
|
|
scoreStudent[i].id=id;
|
|
|
|
|
System.out.println("输入学生姓名");
|
|
|
|
|
String name= scanner.next();
|
|
|
|
|
scoreStudent[i].stuName=name;
|
|
|
|
|
System.out.println("课程名称");
|
|
|
|
|
String scoreName=scanner.next();
|
|
|
|
|
scoreStudent[i].scoreName=scoreName;
|
|
|
|
|
System.out.println("成绩");
|
|
|
|
|
int score=scanner.nextInt();
|
|
|
|
|
scoreStudent[i].score=score;
|
|
|
|
|
numStudent++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("现在有"+numStudent+"人");
|
|
|
|
|
}
|
|
|
|
|
private static void searchScore(Scanner scanner){//查询信息
|
|
|
|
|
System.out.println("请输入查询该学生的学号");
|
|
|
|
|
String stu_id=scanner.next();
|
|
|
|
|
boolean flag=true;
|
|
|
|
|
for(int i=0;i<numStudent;i++){
|
|
|
|
|
Score s=scoreStudent[i];
|
|
|
|
|
if(s.stu_id.equals(stu_id)){
|
|
|
|
|
System.out.println("该学生的名字为:"+s.stuName);
|
|
|
|
|
System.out.println("该学生的学号为:"+s.stu_id);
|
|
|
|
|
System.out.println("该学生的序号为:"+s.id);
|
|
|
|
|
System.out.println("该学生的所选课程为:"+s.scoreName);
|
|
|
|
|
System.out.println("该学生的课程成绩为:"+s.score);
|
|
|
|
|
flag=false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(flag){
|
|
|
|
|
System.out.println("没有该学生的信息,请重新输入");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static boolean contains(String stu_id){//判断是否重复
|
|
|
|
|
for(int i=0;i<numStudent;i++){
|
|
|
|
|
Score s=scoreStudent[i];
|
|
|
|
|
if(s.stu_id.equals(stu_id)){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
private static void updateScore(Scanner sc){//修改
|
|
|
|
|
System.out.println("请输入该同学的学号");
|
|
|
|
|
String stu_id=sc.next();
|
|
|
|
|
if(!contains(stu_id)){
|
|
|
|
|
System.out.println("该同学学号不存在!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for(int i=0;i<numStudent;i++){
|
|
|
|
|
Score s=scoreStudent[i];
|
|
|
|
|
if(s.stu_id.equals(stu_id)){
|
|
|
|
|
System.out.println("您要修改的同学的姓名为"+s.stuName);
|
|
|
|
|
System.out.println("请输入该同学的新成绩");
|
|
|
|
|
scoreStudent[i].score=sc.nextInt();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static void deleteScore(Scanner sc){
|
|
|
|
|
int k=0;
|
|
|
|
|
System.out.println("请输入您有删除的学生学号");
|
|
|
|
|
String stu_id=sc.next();
|
|
|
|
|
if(!contains(stu_id)){
|
|
|
|
|
System.out.println("您输入的学号不存在");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for(int i=0;i<numStudent;i++){
|
|
|
|
|
Score s=scoreStudent[i];
|
|
|
|
|
if(s.stu_id.equals(stu_id)){
|
|
|
|
|
k=i;
|
|
|
|
|
System.out.println("您要删除的是"+s.stuName+"同学");
|
|
|
|
|
System.out.println("是否删除,输入Y或N,Y代表删除,N代表不删除");
|
|
|
|
|
String temp=sc.next();
|
|
|
|
|
if(temp.equals("N")||temp.equals("n")){
|
|
|
|
|
System.out.println("信息没有删除");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(int i=k;i<numStudent;i++){//循环判断条件-1或不减1无太大差别
|
|
|
|
|
scoreStudent[i]=scoreStudent[i+1];
|
|
|
|
|
}
|
|
|
|
|
numStudent--;
|
|
|
|
|
System.out.println("信息删除成功!");
|
|
|
|
|
}
|
|
|
|
|
private static void sumScore(Scanner sc){
|
|
|
|
|
System.out.println("一共有"+numStudent+"人");
|
|
|
|
|
int max=scoreStudent[0].score;
|
|
|
|
|
int min=scoreStudent[0].score;
|
|
|
|
|
double sum=0;
|
|
|
|
|
for (int i = 0; i < numStudent; i++) {
|
|
|
|
|
if(scoreStudent[i].score>max){
|
|
|
|
|
max=scoreStudent[i].score;
|
|
|
|
|
}
|
|
|
|
|
if(scoreStudent[i].score<min){
|
|
|
|
|
min=scoreStudent[i].score;
|
|
|
|
|
}
|
|
|
|
|
sum+=scoreStudent[i].score;
|
|
|
|
|
}
|
|
|
|
|
System.out.println("最高分为"+max);
|
|
|
|
|
System.out.println("最低分为"+min);
|
|
|
|
|
System.out.printf("平均分%.2f",sum/numStudent);
|
|
|
|
|
}
|
|
|
|
|
private static void sortScore(Scanner sc){
|
|
|
|
|
for (int i = numStudent; i >0 ; i--) {
|
|
|
|
|
for(int j=0;j<i-1;j++){
|
|
|
|
|
Score s=new Score();
|
|
|
|
|
if(scoreStudent[j].score>scoreStudent[j+1].score){
|
|
|
|
|
s=scoreStudent[j];
|
|
|
|
|
scoreStudent[j]=scoreStudent[j+1];
|
|
|
|
|
scoreStudent[j+1]=s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println("展示排序后结果");
|
|
|
|
|
displayScore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
class Score{
|
|
|
|
|
int id;//序号
|
|
|
|
|
String stuName;//学生姓名
|
|
|
|
|
String stu_id;//学生学号
|
|
|
|
|
String scoreName;//课程名称
|
|
|
|
|
int score;//分数
|
|
|
|
|
public String toString(){
|
|
|
|
|
return "序号:"+id+",学号"+stu_id
|
|
|
|
|
+",姓名:"+stuName+",课程名称:"+scoreName+",分数:"+score;
|
|
|
|
|
}
|
|
|
|
|
}
|