Java Reference
In-Depth Information
that represents one person in the address book. The class contains fields for the address
ID, first name, last name, email address and phone number, as well as set and get methods
for manipulating these fields.
1
// Fig. 24.30: Person.java
2
// Person class that represents an entry in an address book.
3
public class Person
4
{
5
private int addressID;
6
private String firstName;
7
private String lastName;
8
private String email;
9
private String phoneNumber;
10
11
// constructor
12
public Person()
13
{
14
}
15
16
// constructor
17
public Person( int addressID, String firstName, String lastName,
18
String email, String phoneNumber)
19
{
20
setAddressID(addressID);
21
setFirstName(firstName);
22
setLastName(lastName);
23
setEmail(email);
24
setPhoneNumber(phoneNumber);
25
}
26
27
// sets the addressID
28
public void setAddressID( int addressID)
29
{
30
this .addressID = addressID;
31
}
32
33
// returns the addressID
34
public int getAddressID()
35
{
36
return addressID;
37
}
38
39
// sets the firstName
40
public void setFirstName(String firstName)
41
{
42
this .firstName = firstName;
43
}
44
45
// returns the first name
46
public String getFirstName()
47
{
Fig. 24.30 | Person class that represents an entry in an AddressBook . (Part 1 of 2.)
Search WWH ::




Custom Search