summaryrefslogtreecommitdiff
path: root/src/Q1/AddressBook.java
blob: 4b69d186fe94ab89fc6c0a3567c27fd27cfe90f4 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/**
 * Assignment 1, COMP268 Class: AddressBook.java Purpose: Represents a contact from an address book.
 *
 * @author: mo khan Student ID: 3431709 Date: May 6, 2019 Version 1.0
 */
package Q1;

import java.util.Objects;

public class AddressBook implements Comparable<AddressBook> {
  private String businessPhone;
  private String cellPhone;
  private String facebookId;
  private String firstName = "";
  private String homeAddress;
  private String homePhone;
  private String lastName = "";
  private String middleName = "";
  private String personalWebSite;
  private String skypeId;

  /** Create a new instance of class AddressBook. Initialize all fields to a blank string. */
  public AddressBook() {
    this("");
  }

  /**
   * Create a new instance of class AddressBook. Initialize the firstName and set all other fields
   * to a blank string.
   *
   * @param firstName the first name for the contact.
   */
  public AddressBook(String firstName) {
    this(firstName, "", "");
  }

  /**
   * Create a new instance of class AddressBook. Initialize the first name, middle name and last
   * name. Set all other fields to a blank string.
   *
   * @param firstName the first name of the contact.
   * @param middleName the middle name of the contact.
   * @param lastName the last name of the contact.
   */
  public AddressBook(String firstName, String middleName, String lastName) {
    this(firstName, middleName, lastName, "", "", "", "", "", "", "");
  }

  /**
   * Create a new instance of class AddressBook. Initialize the first name, middle name, last name,
   * business phone number, cell phone number, Facebook Id, home address, home phone number,
   * personal website and Skype Id of the contact.
   *
   * @param firstName the first name of the contact.
   * @param middleName the middle name of the contact.
   * @param lastName the last name of the contact.
   * @param businessPhone the phone number of the contact.
   * @param cellPhone the cell phone number of the contact.
   * @param facebookId the Facebook Id of the contact.
   * @param homeAddress the home address of the contact.
   * @param homePhone the home phone number of the contact.
   * @param personalWebSite the website of the contact.
   * @param skypeId the Skype Id of the contact.
   */
  public AddressBook(
      String firstName,
      String middleName,
      String lastName,
      String businessPhone,
      String cellPhone,
      String facebookId,
      String homeAddress,
      String homePhone,
      String personalWebSite,
      String skypeId) {
    this.businessPhone = businessPhone;
    this.cellPhone = cellPhone;
    this.facebookId = facebookId;
    this.firstName = firstName;
    this.homeAddress = homeAddress;
    this.homePhone = homePhone;
    this.lastName = lastName;
    this.middleName = middleName;
    this.personalWebSite = personalWebSite;
    this.skypeId = skypeId;
  }

  /**
   * Returns the business phone number.
   *
   * @return the business phone number.
   */
  public String getBusinessPhone() {
    return this.businessPhone;
  }

  /**
   * Returns the cell phone number.
   *
   * @return the cell phone number.
   */
  public String getCellPhone() {
    return this.cellPhone;
  }

  /**
   * Returns the Facebook Id.
   *
   * @return the Facebook Id
   */
  public String getFacebookId() {
    return this.facebookId;
  }

  /**
   * Returns the first name.
   *
   * @return the first name
   */
  public String getFirstName() {
    return this.firstName;
  }

  /**
   * Returns the home address.
   *
   * @return the home address
   */
  public String getHomeAddress() {
    return this.homeAddress;
  }

  /**
   * Returns the home phone number.
   *
   * @return the phone number
   */
  public String getHomePhone() {
    return this.homePhone;
  }

  /**
   * Returns the last name.
   *
   * @return the last name
   */
  public String getLastName() {
    return this.lastName;
  }

  /**
   * Returns the middle name.
   *
   * @return the middle name
   */
  public String getMiddleName() {
    return this.middleName;
  }

  /**
   * Returns the personal website.
   *
   * @return the website name
   */
  public String getPersonalWebSite() {
    return this.personalWebSite;
  }

  /**
   * Returns the Skype Id.
   *
   * @return the skype id
   */
  public String getSkypeId() {
    return this.skypeId;
  }

  /**
   * Sets the business phone number.
   *
   * @param value The new phone number.
   */
  public void setBusinessPhone(String value) {
    this.businessPhone = value;
  }

  public void setCellPhone(String value) {
    this.cellPhone = value;
  }

  public void setFacebookId(String value) {
    this.facebookId = value;
  }

  public void setFirstName(String name) {
    this.firstName = name;
  }

  public void setHomeAddress(String address) {
    this.homeAddress = address;
  }

  public void setHomePhone(String value) {
    this.homePhone = value;
  }

  public void setLastName(String name) {
    this.lastName = name;
  }

  public void setMiddleName(String name) {
    this.middleName = name;
  }

  public void setPersonalWebSite(String value) {
    this.personalWebSite = value;
  }

  public void setSkypeId(String value) {
    this.skypeId = value;
  }

  public static String compareNames(String name1, String name2) {
    return Integer.toString(name1.compareTo(name2));
  }

  public int compareTo(AddressBook other) {
    return this.firstName.compareTo(other.firstName)
        + this.middleName.compareTo(other.middleName)
        + this.lastName.compareTo(other.lastName);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof AddressBook)) return false;
    AddressBook that = (AddressBook) o;
    return Objects.equals(businessPhone, that.businessPhone)
        && Objects.equals(cellPhone, that.cellPhone)
        && Objects.equals(facebookId, that.facebookId)
        && Objects.equals(firstName, that.firstName)
        && Objects.equals(homeAddress, that.homeAddress)
        && Objects.equals(homePhone, that.homePhone)
        && Objects.equals(lastName, that.lastName)
        && Objects.equals(middleName, that.middleName)
        && Objects.equals(personalWebSite, that.personalWebSite)
        && Objects.equals(skypeId, that.skypeId);
  }

  @Override
  public int hashCode() {
    return Objects.hash(
        businessPhone,
        cellPhone,
        facebookId,
        firstName,
        homeAddress,
        homePhone,
        lastName,
        middleName,
        personalWebSite,
        skypeId);
  }

  @Override
  public String toString() {
    return this.firstName;
  }
}