一、今日学习内容:
学生管理系统的实现:
源程序代码:
1 package stu;
2 import java.util.Scanner;
3 public class student {
4 Scanner con=new Scanner(System.in);
5 private String stunumber;
6 private String name;
7 private int age;
8 private boolean sex;
9 private double score;
10 public void setStunumber(String stunumber1) {
11 stunumber=stunumber1;
12 }
13 public String getStunumber() {
14 return stunumber;
15 }
16 public void setName(String name1) {
17 name=name1;
18 }
19 public String getName() {
20 return name;
21 }
22 public void setAge(int age1) {
23 age=age1;
24 }
25 public int getAge() {
26 return age;
27 }
28 public void setSex(boolean sex1) {
29 sex=sex1;
30 }
31 public boolean getSex() {
32 return sex;
33 }
34 public void setScore(double score1) {
35 score=score1;
36 }
37 public double getScore() {
38 return score;
39 }
40 student(String stun,String n,int a,boolean se,double sc){
41 stunumber=stun;
42 name=n;
43 age=a;
44 sex=se;
45 score=sc;
46 }
47 public student() {}
48
49 }
1 package stu;
2 import java.util.Scanner;
3 public class studentMange {
4 private static student stu[]=new student[10];
5 private static int n;
6 public studentMange() {
7 for(int i=0;i<5;i++) {
8 stu[i]=new student();
9 }
10 stu[0]=new student("20190001","李明",19,false,89);
11 stu[1]=new student("20190002","张丽",18,true,85);
12 stu[2]=new student("20190003","王非",20,false,77);
13 stu[3]=new student("20190004","孙红",19,true,90);
14 stu[4]=new student("20190005","苏甜",19,true,93);
15 n=5;
16 }
17 //输出学生信息
18 public static void showStudent() {
19 System.out.println("考生信息:");
20 System.out.print("学号"+"\t\t"+"姓名"+"\t"+"年龄"+"\t"+"性别"+"\t"+"成绩"+"\n");
21 for(int i=0;i<n;i++) {
22 System.out.println(stu[i].getStunumber()+"\t"+stu[i].getName()+"\t"+stu[i].getAge()+"\t"+stu[i].getSex()+"\t"+stu[i].getScore());
23 }
24 }
25 //添加学生信息
26 public static void addStudent(String stunumber,String name,int age,boolean sex,double score) {
27 int flag=1;
28 for(int i=0;i<n;i++) {
29 if(stunumber.equals(stu[i].getStunumber())) {
30 System.out.println("该学号已存在!");
31 flag=0;
32 }
33 }
34 if(flag==1) {
35 stu[n]=new student();
36 stu[n].setStunumber(stunumber);
37 stu[n].setName(name);
38 stu[n].setAge(age);
39 stu[n].setSex(sex);
40 stu[n].setScore(score);
41 showStudent();
42 System.out.println(stu[n].getStunumber()+"\t"+stu[n].getName()+"\t"+stu[n].getAge()+"\t"+stu[n].getSex()+"\t"+stu[n].getScore());
43 n=n+1;
44 }
45 }
46 //删除学生信息
47 public static void deleteStudent(String stunumber) {
48 for(int i=0;i<n;i++) {
49 if(stunumber.equals(stu[i].getStunumber())) {
50 for(int j=i;j<n-1;j++) {
51 stu[j]=stu[j+1];
52 }
53 }
54 }
55 n=n-1;
56 stu[n]=null;
57 showStudent();
58 }
59 //修改学生信息
60 public static void updateStudent(String stunumber,String name,int age,boolean sex,double score) {
61 Scanner con=new Scanner(System.in);
62 System.out.println("请输入要修改的学生学号:");
63 String stun1=con.next();
64 for(int i=0;i<n;i++) {
65 if(stun1.equals(stu[i].getStunumber())) {
66 stu[i].setStunumber(stunumber);
67 stu[i].setName(name);
68 stu[i].setAge(age);
69 stu[i].setSex(sex);
70 stu[i].setScore(score);
71 }
72 }
73 showStudent();
74 }
75 //查找学生信息
76 public static void selectStudent(String stunumber) {
77 int flag=0;
78 for(int i=0;i<n;i++) {
79 if(stunumber.equals(stu[i].getStunumber())) {
80 System.out.println("查询到的学生信息为:");
81 System.out.println(stu[i].getStunumber()+"\t"+stu[i].getName()+"\t"+stu[i].getAge()+"\t"+stu[i].getSex()+"\t"+stu[i].getScore());
82 flag=1;
83 }
84 }
85 if(flag==0)System.out.println("查询不到该信息!");
86 }
87
88 public static void main(String[] args) {
89 studentMange sm=new studentMange();
90 int n,m;
91 Scanner con=new Scanner(System.in);
92 System.out.println("**********************************************");
93 System.out.println(" 石家庄铁道大学信息科学与技术学院 ");
94 System.out.println(" 学生信息管理系统 v2.0 ");
95 System.out.println("**********************************************");
96 System.out.println(" 1.遍历输出学生信息 ");
97 System.out.println(" 2.新学生信息录入 ");
98 System.out.println(" 3.删除学生信息 ");
99 System.out.println(" 4.修改学生信息 ");
100 System.out.println(" 5.查询学生信息 ");
101 System.out.println("**********************************************");
102 do {
103 System.out.print("请选择序号:");
104 n=con.nextInt();
105 switch(n) {
106 case 1:sm.showStudent();break;
107 case 2:{
108 System.out.print("请输入要录入的学生信息(学号 姓名 年龄 性别 成绩):");
109 String stunumber1=con.next();
110 String name1=con.next();
111 int age1=con.nextInt();
112 boolean sex1=con.nextBoolean();
113 double score1=con.nextDouble();
114 addStudent(stunumber1,name1,age1,sex1,score1);
115 break;
116 }
117 case 3:{
118 System.out.println("请输入要删除学生的学号:");
119 String s=con.next();
120 deleteStudent(s);
121 break;
122 }
123 case 4:{
124 System.out.println("请输入修改后的学生信息(学号 姓名 年龄 性别 成绩):");
125 String stunumber2=con.next();
126 String name2=con.next();
127 int age2=con.nextInt();
128 boolean sex2=con.nextBoolean();
129 double score2=con.nextDouble();
130 updateStudent(stunumber2,name2,age2,sex2,score2);
131 break;
132 }
133 case 5:{
134 System.out.println("请输入要查询的学生学号:");
135 String s=con.next();
136 selectStudent(s);
137 break;
138 }
139 }
140 System.out.println("请选择下一步要进行的功能:1、继续 2、退出"); //继续或选择退出
141 m=con.nextInt();
142 if(m==2) break;
143 }while(m!=2);
144 }
145
146 }
二、遇到的问题:
代码的编写耗时长,实现出现的错误较多,挨个百度,有的错误是不小心打错的字母,还需细心。
三、今后计划
继续完成例题的验证。

浙公网安备 33010602011771号