forked from JustinSDK/JavaSE6Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
42 lines (34 loc) · 888 Bytes
/
Student.java
File metadata and controls
42 lines (34 loc) · 888 Bytes
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
package onlyfun.caterpillar;
public class Student {
private String name; // 固定 15 字元
private int score;
public Student() {
setName("noname");
}
public Student(String name, int score) {
setName(name);
this.score = score;
}
public void setName(String name) {
StringBuilder builder = null;
if(name != null)
builder = new StringBuilder(name);
else
builder = new StringBuilder(15);
builder.setLength(15);
this.name = builder.toString();
}
public void setScore(int score) {
this.score = score;
}
public String getName() {
return name;
}
public int getScore() {
return score;
}
// 每筆資料固定寫入34位元組
public static int size() {
return 34;
}
}