KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > Student


1 package examples;
2
3 import java.util.Collections JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.LinkedHashSet JavaDoc;
6 import java.util.Set JavaDoc;
7
8
9 /**
10  * @author Ben Wang
11  */

12 public class Student extends Person
13 {
14    protected String JavaDoc school;
15    protected Set JavaDoc courses = new LinkedHashSet JavaDoc();
16
17    public void setSchool(String JavaDoc school)
18    {
19       this.school = school;
20    }
21
22    public String JavaDoc getSchool()
23    {
24       return this.school;
25    }
26    
27    public void addCourse(Course course)
28    {
29       courses.add(course);
30    }
31    
32    public void removeCourse(Course course)
33    {
34       courses.remove(course);
35    }
36    
37    public Set JavaDoc getCourses()
38    {
39       return Collections.unmodifiableSet(courses);
40    }
41
42    public String JavaDoc toString()
43    {
44       StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
45       buf.append("{Name = " +name).append(", School = " +school);
46       if (address != null)
47          buf.append(", Address = " + address.getSimpleAddress());
48       buf.append("}\n");
49       buf.append("Courses:\n");
50       for (Iterator JavaDoc iter = getCourses().iterator(); iter.hasNext(); )
51          buf.append(iter.next());
52
53       return buf.toString();
54    }
55
56 }
57
Popular Tags