class Crowd
1: //Crowd.java
2:
3: import java.util.*;
4:
5: class Crowd
6: {
7: //Person store - only accessible through methods of this class
8: private Vector people;
9:
10: //Constructors
11: public Crowd()
12: {
13: //Create default Vector object to hold people
14: people = new Vector();
15: }
16: public Crowd(int numPersons)
17: {
18: //Create Vector object to hold people with given capacity
19: people = new Vector(numPersons);
20: }
21:
22:
23: //Add a person to the crowd
24: public boolean add(Person someone)
25: {
26: return people.add(someone); //Use the Vector method to add
27: }
28:
29: //Get the person at a given index
30: Person get(int index)
31: {
32: return (Person)people.get(index);
33: }
34:
35: //Get number of persons in crowd
36: public int size()
37: {
38: return people.size();
39: }
40:
41: //Get people store capacity
42: public int capacity()
43: {
44: return people.capacity();
45: }
46:
47: //Get an iterator for the crowd
48: public Iterator iterator()
49: {
50: return people.iterator();
51: }
52:
53: //Sort the people
54: public void sort()
55: {
56: Collections.sort(people); //Use the static sort method
57: }
58: }