forked from xt0fer/BlueJ-People
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
80 lines (71 loc) · 1.57 KB
/
Person.java
File metadata and controls
80 lines (71 loc) · 1.57 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* A person class for a simple BlueJ demo program. Person is used as
* an abstract superclass of more specific person classes.
*
* @author Michael Kölling
* @version 1.0, January 1999
*/
abstract class Person
{
private String name;
private int yearOfBirth;
private Address address;
/**
* Create a person with given name and age.
*/
Person(String name, int yearOfBirth)
{
this.name = name;
this.yearOfBirth = yearOfBirth;
}
/**
* Set a new name for this person.
*/
public void setName(String newName)
{
name = newName;
}
/**
* Return the name of this person.
*/
public String getName()
{
return name;
}
/**
* Set a new birth year for this person.
*/
public void setYearOfBirth(int newYearOfBirth)
{
yearOfBirth = newYearOfBirth;
}
/**
* Return the birth year of this person.
*/
public int getYearOfBirth()
{
return yearOfBirth;
}
/**
* Set a new address for this person.
*/
public void setAddress(String street, String town, String postCode)
{
address = new Address(street, town, postCode);
}
/**
* Return the address of this person.
*/
public Address getAddress()
{
return address;
}
/**
* Return a string representation of this object.
*/
public String toString() // redefined from "Object"
{
return "Name: " + name + "\n" +
"Year of birth: " + yearOfBirth + "\n";
}
}