-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContact.java
More file actions
49 lines (41 loc) · 1.1 KB
/
Contact.java
File metadata and controls
49 lines (41 loc) · 1.1 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
public class Contact{
// Store 3 information of Contact
String name;
private String phone;
private String email;
// Initialize value of Contact`s information
public Contact(String name, String phone, String email) {
this.name = name;
this.phone = phone;
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
// Displays the contact's information.
// Only prints phone and email if the corresponding values are not empty.
public void showInfo() {
System.out.println("Name: " + name);
if (!phone.isEmpty()) {
System.out.println("Phone: " + phone);
}
if (!email.isEmpty()) {
System.out.println("Email: " + email + "\n");
}
}
}