-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFacePamphletProfile.java
More file actions
127 lines (114 loc) · 3.79 KB
/
Copy pathFacePamphletProfile.java
File metadata and controls
127 lines (114 loc) · 3.79 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
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
/*
* File: FacePamphletProfile.java
* ------------------------------
* This class keeps track of all the information for one profile
* in the FacePamphlet social network. Each profile contains a
* name, an image (which may not always be set), a status (what
* the person is currently doing, which may not always be set),
* and a list of friends.
*/
import acm.graphics.*;
import java.util.*;
public class FacePamphletProfile implements FacePamphletConstants {
private String profileName = "";
private String profileStatus = "";
private GImage profileImage = null;
private ArrayList<String> friends = new ArrayList<String>();
/**
* Constructor
* This method takes care of any initialization needed for
* the profile.
*/
public FacePamphletProfile(String name) {
profileName = name+"";
}
/** This method returns the name associated with the profile. */
public String getName() {
return profileName;
}
/**
* This method returns the image associated with the profile.
* If there is no image associated with the profile, the method
* returns null. */
public GImage getImage() {
return profileImage;
}
/** This method sets the image associated with the profile. */
public void setImage(GImage image) {
profileImage = image;
}
/**
* This method returns the status associated with the profile.
* If there is no status associated with the profile, the method
* returns the empty string ("").
*/
public String getStatus() {
return profileStatus;
}
/** This method sets the status associated with the profile. */
public void setStatus(String status) {
profileStatus = status;
}
/**
* This method adds the named friend to this profile's list of
* friends. It returns true if the friend's name was not already
* in the list of friends for this profile (and the name is added
* to the list). The method returns false if the given friend name
* was already in the list of friends for this profile (in which
* case, the given friend name is not added to the list of friends
* a second time.)
*/
public boolean addFriend(String friend) {
if(!friends.contains(friend)){
friends.add(friend);
return true;
} else {
return false;
}
}
/**
* This method removes the named friend from this profile's list
* of friends. It returns true if the friend's name was in the
* list of friends for this profile (and the name was removed from
* the list). The method returns false if the given friend name
* was not in the list of friends for this profile (in which case,
* the given friend name could not be removed.)
*/
public boolean removeFriend(String friend) {
if(friends.contains(friend)) {
friends.remove(friend);
return true;
} else {
return false;
}
}
/**
* This method returns an iterator over the list of friends
* associated with the profile.
*/
public Iterator<String> getFriends() {
Iterator<String> iter = friends.iterator();
return iter;
}
/**
* This method returns a string representation of the profile.
* This string is of the form: "name (status): list of friends",
* where name and status are set accordingly and the list of
* friends is a comma separated list of the names of all of the
* friends in this profile.
*
* For example, in a profile with name "Alice" whose status is
* "coding" and who has friends Don, Chelsea, and Bob, this method
* would return the string: "Alice (coding): Don, Chelsea, Bob"
*/
public String toString() {
String str = "" + profileName +" (" +profileStatus+") ";
for (int i=0; i<friends.size(); i++) {
str = str + friends.get(i);
if(i<friends.size()-1) {
str = str+", ";
}
}
return str;
}
}