本文实例为大家分享了java实现选课系统的具体代码,供大家参考,具体内容如下
这个程序主要是练习io(文件读写,序列化),集合框架的使用
学生端可以实现,查找课程,增加选课,删除选课的功能
管理端可以实现对备选课程,学生信息的增删查改
缺点:登陆操作没有实现密码验证和多态。
另外map对象明明put了,可是get的时候竟然会取到null,而且尝试多次,有时候成功,有时候取到null,并不确定。据说这是由多线程引起的map取值为null,因为多线程部分还没开始学习,所以也没做修改。
?
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
|
//课程信息
package selectcourse;
import java.io.serializable;
public class course implements serializable{
private string id;
private string name;
public course(string id, string name) {
super ();
this .id = id;
this .name = name;
}
public course() {
super ();
}
public string getid() {
return id;
}
public void setid(string id) {
this .id = id;
}
public string getname() {
return name;
}
public void setname(string name) {
this .name = name;
}
public int hashcode() {
final int prime = 31 ;
int result = 1 ;
result = prime * result + ((id == null ) ? 0 : id.hashcode());
result = prime * result + ((name == null ) ? 0 : name.hashcode());
return result;
}
public boolean equals(object obj) {
if ( this == obj)
return true ;
if (obj == null )
return false ;
if (getclass() != obj.getclass())
return false ;
course other = (course) obj;
if (id == null ) {
if (other.id != null )
return false ;
} else if (!id.equals(other.id))
return false ;
if (name == null ) {
if (other.name != null )
return false ;
} else if (!name.equals(other.name))
return false ;
return true ;
}
public string tostring() {
return "课程号:" + id + " " + "课程名:" + name;
}
}
|
?
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
|
//学生信息
package selectcourse;
import java.io.serializable;
import java.util.hashset;
import java.util.set;
public class student implements serializable,comparable<student>{
private int id;
private string name;
private set<course> courses;
public student( int id, string name) {
super ();
this .id = id;
this .name = name;
this .courses = new hashset<course>();
}
public student() {
super ();
this .id = 0 ;
this .name = null ;
this .courses = new hashset<course>();
}
public int getid() {
return id;
}
public void setid( int id) {
this .id = id;
}
public string getname() {
return name;
}
public void setname(string name) {
this .name = name;
}
public set<course> getcourses() {
return courses;
}
public void setcourses(set<course> courses) {
this .courses = courses;
}
public int hashcode() {
final int prime = 31 ;
int result = 1 ;
result = prime * result + id;
return result;
}
public boolean equals(object obj) {
if ( this == obj)
return true ;
if (obj == null )
return false ;
if (getclass() != obj.getclass())
return false ;
student other = (student) obj;
if (id != other.id)
return false ;
return true ;
}
public string tostring() {
return "学号:" +id+ " " + "姓名:" +name;
}
//遍历输出所选课程
public void travese()
{
if (courses.size()> 0 )
{
for (course course : courses) {
system.out.println(course);
}
}
else
{
system.out.println( "还没有选课" );
}
}
public int compareto(student s) {
int result= this .id-s.id;
return result;
}
}
|
?
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
|