} // AddWife /// <summary> /// Divorces a wife from this man /// </summary> /// <param name="wife">The wife to be divorced</param> // Pre: (wife != null) and (this.hasMarried(wife)) public void RemoveWife(Woman wife) { wifes.Remove(wife); if (wife.HasMarried(this)) { wife.RemoveHusband(this); } // if } // RemoveWife
} // Man /// <summary> /// Adds a new wife to the man's harem /// </summary> /// <param name="wife">The new wife for this lucky man</param> // Pre: wife != null public void AddWife(Woman wife) { wifes.Add(wife); if (!wife.HasMarried(this)) { wife.AddHusband(this); } // if } // AddWife
} // RemoveWife /// <summary> /// Checks whether this man has married the woman passed as a parameter /// </summary> /// <param name="wife">A woman</param> /// <returns>Turn if the man has married the woman passed as a parameter, /// otherwise it returns false</returns> public bool HasMarried(Woman wife) { return(wifes.Contains(wife)); } // HasMarried