I have this Person class with some methods to add, remove and view your friends. For some reason, when I want to view my friend, even though I think I'm calling the right methods the right way, The last Person object (which is carl ) is printed regardless of the object specifications in the method call. What is the problem?
here is the code:
package person;
public class Person {
private static String name;
private static String friends;
public static void main(String[] args) {
Person ted = new Person ("ted");
Person jim = new Person ("jim");
Person todd = new Person ("todd");
Person tom = new Person ("tom");
Person carl = new Person ("carl");
// apparently I'm making a mistake here...
jim.addFriend(zack);
System.out.println(jim.getFriends());
}
public Person (String aName) {
name = aName;
friends = "";
}
public static void addFriend(Person friend) {
friends = friends + friend.name + " ";
}
public static void unFriend (Person nonFriend) {
friends = friends.replace(nonFriend.name + " ", "");
}
public static String getFriends () {
return friends;
}
}