1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import java.util.ArrayList;
  2. import java.util.Iterator;
  3. /**
  4. * A very simple database of people in a university. This class simply stores
  5. * persons and, at request, lists them on standard output.
  6. *
  7. * Written as a first demo program for BlueJ.
  8. *
  9. * @author Michael Kölling
  10. * @version 1.1, March 2002
  11. */
  12. public class Database {
  13. private ArrayList<Person> persons;
  14. /**
  15. * Create a new, empty person database.
  16. */
  17. public Database()
  18. {
  19. persons = new ArrayList<Person>();
  20. }
  21. /**
  22. * Add a person to the database.
  23. */
  24. public void addPerson(Person p)
  25. {
  26. persons.add(p);
  27. }
  28. /**
  29. * List all the persons currently in the database on standard out.
  30. */
  31. public void listAll ()
  32. {
  33. for (Iterator i = persons.iterator(); i.hasNext();) {
  34. System.out.println(i.next());
  35. }
  36. }
  37. }