/*  
 *  This is a crude implementation, ideally, you'd want to keep an array
 *  or other data structure of friends and enemies (here only one of each is
 *  allowed).
 */

class Person {
    private String name; // a Person has a name
    private Person friend, enemy; // a Person has a friend and an enemy
    
    // Create a Person object with name:
    public Person(String name) 
    {
        this.name = name;
    }
    
    // Set current Person's friend to supplied friend:
    public void makeFriends(Person friend) 
    {
        this.friend = friend;
        friend.friend = this;
    }
    
    // Set current Person's friend to supplied friend:
    public void makeEnemies(Person enemy) 
    {
        this.enemy = enemy;               
        // Enforce the addage, see if your enemy has any enemies!
        if( enemy.enemy != null )
            makeFriends(enemy.enemy);   // Make that enemy your friend
        else
            enemy.enemy = this;
    }
    
    // Stringify current Person:
    public String toString() 
    {
        String res = "I am " + name;
        if(friend != null)
            res += "\nmy friend is "+friend.name;
        if(enemy != null)
            res += "\nmy enemy is "+enemy.name+"\n";        
        return res;
    }
}

public class Test {    
    public static void main(String[] args) {
        Person A = new Person("Alan");
        Person B = new Person("Bob");
        Person C = new Person("Cindy");
        
        A.makeEnemies(B);
        C.makeEnemies(B);
        System.out.println("" + A + B + C);        
    }    
}

/*
 *  The following output is generated:
 *
 *  I am Alan
 *  my friend is Cindy
 *  my enemy is Bob
 *  I am Bob
 *  my enemy is Alan
 *  I am Cindy
 *  my friend is Alan
 *  my enemy is Bob
 *
 *  Notice that Bob only has one enemy, this can be fixed by adding arrays, etc.  Feel free
 *  to continue modifying this code, but the above should give you a good place to
 *  start if you were having trouble.
 */

