-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFacePamphletProfile.java
More file actions
138 lines (121 loc) · 3.72 KB
/
Copy pathFacePamphletProfile.java
File metadata and controls
138 lines (121 loc) · 3.72 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
128
129
130
131
132
133
134
135
136
137
138
/*
* 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 {
/**
* Constructor
* This method takes care of any initialization needed for
* the profile.
*/
public FacePamphletProfile(String name) {
this.name=name;
image=null;
status=null;
list=new ArrayList<String>();
Iterator it=list.iterator();
}
/** This method returns the name associated with the profile. */
public String getName() {
return name;
}
/**
* 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 image;
}
/** This method sets the image associated with the profile. */
public void setImage(String name) {
image=new GImage(name);
}
/**
* 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 status;
}
/** This method sets the status associated with the profile. */
public void setStatus(String status) {
this.status=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) {
Iterator it=list.iterator();
if(this.getName()==friend){
return false;
}
while(it.hasNext()){
if(it.next()==friend){
return false;
}
}
list.add(friend);
return true;
}
/**
* 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) {
Iterator it=list.iterator();
while(it.hasNext()){
if(it.next().equals(friend)){
list.remove(friend);
return true;
}
}
return false;
}
/**
* This method returns an iterator over the list of friends
* associated with the profile.
*/
public Iterator<String> getFriends() {
Iterator it=list.iterator();
return it;
}
/**
* 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() {
// You fill this in. Currently always returns the empty string.
return "";
}
private String name;
private GImage image;
private String status;
public List<String> list;
private FacePamphletCanvas Canvas;
Iterator<String> it;
}