-
Notifications
You must be signed in to change notification settings - Fork 0
/
Profile.java
124 lines (108 loc) · 3.37 KB
/
Profile.java
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
/*
Names: Niki & Cheryl, Team Red
Date: 12/3/2023
AD325 - Project 4: Social Media Network
*/
import java.util.ArrayList;
import java.util.List;
public class Profile {
private String name;
private String status;
private List<Profile> friendsList;
public Profile(String name) {
this.name = name;
this.friendsList = new ArrayList<>();
} //end default constructor
public Profile(String name, String status) {
this.name = name;
this.status = status;
this.friendsList = new ArrayList<>();
} //end constructor
/**
* Retrieves the name from the user's profile.
* @return name associated with this profile.
*/
public String getName() {
return name;
}
/**
* Creates or alters the name on the user's profile.
* @param name name associated with this profile.
*/
public void setName(String name) {
this.name = name;
}
/**
* Retrieves the status from the user's profile.
* @return status - e.g. online, busy, or offline.
*/
public String getStatus() {
return status;
}
/**
* Creates or alters the status of the user.
* @param status e.g. online, busy, or offline.
*/
public void setStatus(String status) {
this.status = status;
}
/**
* Retrieves this user's list of friends stored in an ArrayList.
* @return friendsList - a list of this user's friends.
*/
public List<Profile> getFriendsList() {
return friendsList;
}
/**
* Adds a friend to this user's list of friends, stored in an ArrayList.
* @param friend a new profile associated with this user.
*/
public void addFriends(Profile friend) {
friendsList.add(friend);
}
/**
* Removes a friend from this user's list of friends, stored in an ArrayList.
* @param friend profile to be deleted from current user's list.
*/
public void removeFriends(Profile friend) {
friendsList.remove(friend);
}
/**
* Outputs the contents of the profile to console as such:
* Current Profile
* Name: username
* Status: user status
* My Friends:
* Name: friend username Status: friend user status
* -alternately-
* No friends yet
*/
public void printProfile() { //Runtime: O(n), depends on number of friends
System.out.println("---------------Current Profile----------------");
System.out.println("Name: " + name);
System.out.println(" Status: " + status);
System.out.println("\nMy Friends:");
if (friendsList.isEmpty()) {
System.out.println(" No friends yet.");
} else {
for (Profile friend : friendsList) {
System.out.println(" Name: " + friend.getName() + " Status: " + friend.getStatus());
}
}
System.out.println("----------------------------------------------");
}
/**
* A string representation of a profile instance from this user's
* friends list.
* @return A line of text in the following format:
* "friend username Status: user status"
*/
@Override
public String toString() {
String status = "None";
if (getStatus() != null) {
status = getStatus();
}
return " " + getName() + " Status: " + status;
}
}