123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * A person class for a simple BlueJ demo program. Person is used as
  3. * an abstract superclass of more specific person classes.
  4. *
  5. * @author Michael Kölling
  6. * @version 1.0, January 1999
  7. */
  8. abstract class Person
  9. {
  10. private String name;
  11. private int yearOfBirth;
  12. private Address address;
  13. /**
  14. * Create a person with given name and age.
  15. */
  16. Person(String name, int yearOfBirth)
  17. {
  18. this.name = name;
  19. this.yearOfBirth = yearOfBirth;
  20. }
  21. /**
  22. * Set a new name for this person.
  23. */
  24. public void setName(String newName)
  25. {
  26. name = newName;
  27. }
  28. /**
  29. * Return the name of this person.
  30. */
  31. public String getName()
  32. {
  33. return name;
  34. }
  35. /**
  36. * Set a new birth year for this person.
  37. */
  38. public void setYearOfBirth(int newYearOfBirth)
  39. {
  40. yearOfBirth = newYearOfBirth;
  41. }
  42. /**
  43. * Return the birth year of this person.
  44. */
  45. public int getYearOfBirth()
  46. {
  47. return yearOfBirth;
  48. }
  49. /**
  50. * Set a new address for this person.
  51. */
  52. public void setAddress(String street, String town, String postCode)
  53. {
  54. address = new Address(street, town, postCode);
  55. }
  56. /**
  57. * Return the address of this person.
  58. */
  59. public Address getAddress()
  60. {
  61. return address;
  62. }
  63. /**
  64. * Return a string representation of this object.
  65. */
  66. public String toString() // redefined from "Object"
  67. {
  68. return "Name: " + name + "\n" +
  69. "Year of birth: " + yearOfBirth + "\n";
  70. }
  71. }