本文為大家分享了java實現學生成績錄入系統,供大家參考,具體內容如下
1.學生類,包括學生的姓名和各科成績
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
public class score { public string name; public double englishgrade, mathgrade,phyicalgrade, chemicalgrade,biologicalgrade; score() { } public score(string name, double englishgrade, double mathgrade, double phyicalgrade, double chemicalgrade, double biologicalgrade){ this .name = name; this .englishgrade = englishgrade; this .mathgrade = mathgrade; this .phyicalgrade = phyicalgrade; this .chemicalgrade = chemicalgrade; this .biologicalgrade = biologicalgrade; } } |
2.對學生類進行設置,包括設置查找等
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package score; public class scorezip { score[] s = new score[ 5 ]; public void setdata(score name, int index) { //添加成績類到成績數組中 s[index] = name; } public score[] getdata() { //返回學生數組 return s; } public score serchdata(string name) { //查找學生各科成績 for ( int index = 0 ; index < s.length; index++) { if (name != null && s[index] != null ) if (s[index].name.equals(name)){ return s[index]; } } return null ; } } |
3.學生成績錄入及學生成績清單
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
|
package score; import java.util.scanner; public class scorezip2 { public static void main(string[] arr) { scanner sc = new scanner(system.in); scorezip sr = new scorezip(); for ( int i = 0 ; i < 5 ; i++) { //這里定義長度為五的學生成績表 system.out.println( "輸入學生姓名:" ); string name = sc.next(); if (name.equals( "n" )) { break ; } system.out.println( "英語分數:" ); double english = sc.nextdouble(); system.out.println( "數學分數:" ); double math = sc.nextdouble(); system.out.println( "物理分數:" ); double physical = sc.nextdouble(); system.out.println( "化學分數:" ); double chemical = sc.nextdouble(); system.out.println( "生物分數:" ); double biology = sc.nextdouble(); score s = new score(name, english,math,physical,chemical,biology); sr.setdata(s, i); } system.out.println( "=========================================" + "學生成績表======================================" ); system.out.println( "姓名\t\t英語成績\t\t數學成績\t\t物理成績\t\t化學成績\t\t生物成績" ); score[] b = sr.getdata(); for (score s : b) { if (s == null ) { break ; } system.out.println(s.name + "\t\t" + s.englishgrade+ "\t\t" +s.mathgrade + "\t\t" +s.phyicalgrade+ "\t\t" +s.chemicalgrade+ "\t\t" +s.biologicalgrade); } system.out.println( "是否查找學生成績? 是y 否n" ); string flag = sc.next(); if (flag.equals( "y" )){ system.out.println( "輸入要查找的學生名:" ); string name = sc.next(); score s = sr.serchdata(name); if (s == null ) { system.out.println( "對不起,沒有此學生名" ); } else { double mg = s.mathgrade; double eg = s.englishgrade; double pg = s.phyicalgrade; double cg= s.chemicalgrade; double bg = s.biologicalgrade; double submit = mg+eg+pg+cg+bg; system.out.println( "要查找的學生為:" + name + "\n數學成績為:" + mg + "\n英語成績為:" + eg+ "\n物理成績為:" + pg+ "\n化學成績為:" + cg + "\n生物成績為:" + bg+ "\n總成績成績為:" + submit); } } } } |
結果圖:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://blog.csdn.net/qq_34122768/article/details/52088940