When person 1 become partner with person 3, person 2 should no longer have person 1 as partner and person 4 should no longer have person 3 as partner. How should I solve this?
public class Person {
private String name;
private Person partner;
public Person(String name){
this.name = name;
}
public void setPartner(Person partner){
this.partner = partner;
partner.partner = this;
}
public static void main(String[] args) {
Person one = new Person("1");
Person two = new Person("2");
Person three = new Person("3");
Person four = new Person("4");
one.setPartner(two);
three.setPartner(four);
one.setPartner(three);
//Person two is still partner with person 1
//and person four is still partner with person 3
}