本文實例為大家分享了java學生成績管理系統的具體代碼,供大家參考,具體內容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
/* *@copyright by lzyrapx on 2016/4/12. *@name:java學生成績管理系統. *@功能:學生相關信息,錄入,查詢,統計,修改等.... *@ps:圖形界面的學生管理系統不要求就不做了. */ import java.util.scanner; import java.lang.*; import java.io.*; class student { private static student[] s= new student[ 100 ]; //錄入學生上限 int n= 0 ; private string name; private int num; private string classage; private int chinese; private int math; private int english; //判斷是否有錄入學生信息 public void judge() throws ioexception { int i; char ch; string str; scanner in= new scanner(system.in); if (n== 0 ) { system.out.println( "你還沒有錄入任何學生信息,是否錄入(y/n):" ); str=in.next(); ch=str.charat( 0 ); while (ch!= 'y' &&ch!= 'y' &&ch!= 'n' &&ch!= 'n' ) { system.out.println( "輸入有誤,請重新輸入:" ); str=in.next(); ch=str.charat( 0 ); } if (ch== 'y' ||ch== 'y' ) { this .add(); } if (ch== 'n' ||ch== 'n' ) { this .menu(); } } } //菜單 public void menu() throws ioexception //將異常拋出,調用這個方法去處理異常,如果main方法也將異常拋出,則交給java虛擬機來處理,下同. { int a; scanner in= new scanner(system.in); system.out.println( "*************學生信息管理系統*************" ); system.out.println( "***** 1.錄入學生信息 ******" ); system.out.println( "***** 2.顯示學生信息 ******" ); system.out.println( "***** 3.修改學生信息 ******" ); system.out.println( "***** 4.刪除學生信息 ******" ); system.out.println( "***** 5.查看學生信息 ******" ); system.out.println( "***** 0.退出管理系統 ******" ); system.out.println( "******************************************" ); system.out.print( "請選擇(0~5):" ); a=in.nextint(); while (a< 0 ||a> 5 ) { system.out.print( "輸入無效,請重新輸入:" ); a=in.nextint(); } switch (a) { case 1 : this .add(); break ; case 2 : this .show(); break ; case 3 : this .modif(); break ; case 4 : this .delete(); break ; case 5 : this .look(); break ; case 0 :system.out.println( "成功退出系統!!!" );system.exit( 0 ); break ; } } //錄入學生信息 public void add() throws ioexception { string str,str1,str2; int i,num1,t= 1 ; char ch,ch1; filewriter fw= new filewriter( "e://student.txt" , true ); //將學生信息錄入指定的txt文件中 fw.write( " 錄入的學生信息列表\r\n\r\n學號 姓名 班級 語文成績 數學成績 英語成績\r\n" ); scanner in= new scanner(system.in); while (t== 1 ) { system.out.println( "請輸入學生學號:" ); num1=in.nextint(); //判斷學號是否重復 for (i= 0 ;i<n;i++) { while (s[i].num==num1) { system.out.println( "已存在此學號,請重新輸入" ); system.out.print( "請輸入學號:" ); num1=in.nextint(); } } s[n].num=num1; str2=string.valueof(num1); fw.write(str2+ " " ); system.out.println(); system.out.println( "請輸入學生姓名:" ); s[n].name=in.next(); fw.write(s[n].name+ " " ); system.out.println(); system.out.println( "請輸入學生班級:" ); s[n].classage=in.next(); fw.write(s[n].classage+ " " ); system.out.println( "請輸入學生語文成績:" ); s[n].chinese=in.nextint(); fw.write(s[n].chinese+ " " ); system.out.println( "請輸入學生數學成績:" ); s[n].math=in.nextint(); fw.write(s[n].chinese+ " " ); system.out.println( "請輸入學生英語成績:" ); s[n].english=in.nextint(); fw.write(s[n].english+ "\r\n" ); ++n; fw.close(); system.out.println(); system.out.println( "是否繼續添加(y/n)" ); str=in.next(); ch=str.charat( 0 ); while (ch!= 'n' &&ch!= 'n' &&ch!= 'y' &&ch!= 'y' ) { system.out.println( "輸入無效,請重新輸入:" ); str=in.next(); ch=str.charat( 0 ); } if (ch== 'n' ||ch== 'n' ) { break ; } } system.out.println(); system.out.print( "是否返回系統主菜單(y/n)" ); str1=in.next(); ch1=str1.charat( 0 ); while (ch1!= 'y' &&ch1!= 'y' &&ch1!= 'n' &&ch1!= 'n' ) { system.out.println( "輸入無效,請重新輸入:" ); str1=in.next(); ch1=str1.charat( 0 ); } if (ch1== 'y' ||ch1== 'y' ) { this .menu(); } if (ch1== 'n' ||ch1== 'n' ) { system.out.println( "" ); system.out.println( "你已退出系統!!!" ); system.exit( 0 ); } } //顯示學生信息 public void show() throws ioexception { int i; this .judge(); system.out.println( "本次操作共錄入" +n+ "位學生!" ); system.out.println( "你錄入的學生信息如下:" ); system.out.println(); system.out.println( "學號\t姓名\t班級\t語文\t數學\t英語" ); for (i= 0 ;i<n;i++) { system.out.println(s[i].num+ " " +s[i].name+ " " +s[i].classage+ " " +s[i].chinese+ " " +s[i].math+ " " +s[i].english); } system.out.println( "系統返回主菜單!" ); this .menu(); } //刪除學生信息 public void delete() throws ioexception { this .judge(); int j= 0 ,t= 0 ,k= 0 ,num1; char ch; string str; scanner pin= new scanner(system.in); system.out.println( "請輸入要刪除的學號:" ); num1=pin.nextint(); for (j= 0 ;j<n;j++) { if (s[j].num==num1) { k= 1 ; t=j; } } if (k== 0 ) { system.out.println( "對不起!你要刪除的學號不存在!" ); system.out.println( "系統將返回主菜單!" ); this .menu(); } if (k== 1 ) { system.out.println( "你要刪除的學生信息如下:" ); //打印管理員要刪除的學生信息 system.out.println( "學號\t姓名\t班級" ); //本功能暫時不備擴展性 system.out.println(s[t].num+ " " +s[t].name+ " " +s[t].classage); system.out.println(); system.out.println( "你確定要刪除(y/n):" ); str=pin.next(); ch=str.charat( 0 ); while (ch!= 'y' &&ch!= 'y' &&ch!= 'n' &&ch!= 'n' ) { system.out.println( "輸入無效,請重新輸入:" ); str=pin.next(); ch=str.charat( 0 ); } if (ch== 'n' ||ch== 'n' ) { system.out.println(); system.out.println( "系統返回主菜單!" ); this .menu(); } if (ch== 'y' ||ch== 'y' ) { for (j=t;j<n- 1 ;j++) { s[j]=s[j+ 1 ]; } n--; system.out.println( "學生數據成功刪除!" ); system.out.println( "系統返回主菜單!" ); this .menu(); } } } //查看學生信息 public void look() throws ioexception { filereader fr= new filereader( "e://student.txt" ); //查看txt中的學生信息 int a; while ((a=fr.read())!=- 1 ) { system.out.print(( char )a); } fr.close(); system.out.println( "系統返回主菜單!" ); system.out.println(); this .menu(); } //修改學生信息 public void modif() throws ioexception { this .judge(); int j= 0 ,t= 0 ,k= 0 ,num2,num3,moi,c= 1 ; char ch; string str,str1,str2; scanner pin= new scanner(system.in); system.out.println( "請輸入要修改的學號:" ); num2=pin.nextint(); for (j= 0 ;j<n;j++) { if (s[j].num==num2) { k= 1 ; t=j; } } if (k== 0 ) { system.out.println( "對不起!你要修改的學號不存在!" ); system.out.println( "系統將返回主菜單!" ); this .menu(); } if (k== 1 ) { //打印將要要刪除的學生信息 system.out.println( "你要修改的學生信息如下:" ); system.out.println( "學號\t姓名\t班級" ); system.out.println(s[t].num+ " " +s[t].name+ " " +s[t].classage); system.out.println( "語文\t數學\t英語" ); system.out.println(s[t].chinese+ " " +s[t].math+ " " +s[t].english); system.out.println(); system.out.println( "你確定要修改(y/n):" ); str=pin.next(); ch=str.charat( 0 ); while (ch!= 'y' &&ch!= 'y' &&ch!= 'n' &&ch!= 'n' ) { system.out.println( "輸入無效,請重新輸入:" ); str=pin.next(); ch=str.charat( 0 ); } if (ch== 'n' ||ch== 'n' ) { system.out.println(); system.out.println( "系統返回主菜單!" ); this .menu(); } while (c== 1 ) { if (ch== 'y' ||ch== 'y' ) { system.out.println( "****************************************" ); system.out.println( "***** 1.修改學號 *****" ); system.out.println( "***** 2.修改班級 *****" ); system.out.println( "***** 3.修改姓名 *****" ); system.out.println( "****************************************" ); system.out.println( "請選擇:" ); moi=pin.nextint(); switch (moi) { case 1 :system.out.print( "請輸入新的學號:" );num3=pin.nextint();s[t].num=num3; break ; case 2 :system.out.print( "請輸入新的班級:" );str1=pin.next();s[t].classage=str1; break ; case 3 :system.out.print( "請輸入新的姓名:" );str2=pin.next();s[t].name=str2; break ; } system.out.println( "數據已成功修改!" ); } system.out.print( "是否繼續修改(y/n)" ); str=pin.next(); ch=str.charat( 0 ); system.out.println(); while (ch!= 'y' &&ch!= 'y' &&ch!= 'n' &&ch!= 'n' ) { system.out.print( "輸入無效,請重新輸入:" ); str=pin.next(); ch=str.charat( 0 ); } if (ch== 'n' ||ch== 'n' ) { break ; } } } system.out.println(); system.out.println( "系統返回主菜單!" ); this .menu(); } public static void main(string[] args) throws ioexception { student stu= new student(); for ( int i= 0 ;i< 100 ;i++) { s[i]= new student(); } stu.menu(); } } |
部分效果圖:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://blog.csdn.net/liangzhaoyang1/article/details/51133198