/**
 * A group of one, two, or three people.
 */
public class Group {

  /** The first group member's name. */
  private String member1;

  /** The second group member's name. */
  private String member2;

  /** The third group member's name. */
  private String member3;

  /**
   * Construct a Group with one member, named m1.
   * @param m1 the first group member.
   */
  public Group(String m1) {
    this.member1= m1;
  }

  /**
   * Construct a Group with two members, named m1 and m2.
   * @param m1 the first group member.
   * @param m2 the second group member.
   */
  public Group(String m1, String m2) {
    this(m1);
    this.member2= m2;
  }

  /**
   * Construct a Group with three members, named m1, m2, and m3.
   * @param m1 the first group member.
   * @param m2 the second group member.
   * @param m3 the second group member.
   */
  public Group(String m1, String m2, String m3) {
    this(m1, m2);
    this.member3= m3;
  }

  /**
   * Return a String representation of this object, consisting of the three
   * member names.
   * @return a String representation of this object, consisting of the three
   * member names.
   */
  public String toString() {
    String result= this.member1;

    if (member2 != null) {
      result= result + " " + member2;
    }

    if (member3 != null) {
      result= result + " " + member3;
    }

    return result;
  }

  /**
   * Return true if o is an instance of Group, o is not null, and this
   * Group is equal to o.
   * @return true iff all members' names are equal.
   */
  public boolean equals(Object o) {
    return o instanceof Group
      && equals(this.member1, ((Group) o).member1)
      && equals(this.member2, ((Group) o).member2)
      && equals(this.member3, ((Group) o).member3);
  }

  /**
   * Return whether s1 and s2 are both null or represent the same String.
   * @return true s1 and s2  are both null or represent the same String.
   */
  public static boolean equals(String s1, String s2) {
    return (s1 == null && s2 == null)
      || (s1 != null && s1.equals(s2));
  }

  /**
   * Test Group.java.
   * @param args this parameter is ignored.
   */
  public static void main(String[] args) {
    Group g1= new Group("c2feedme");
    System.out.println(g1.equals(g1));
    Group g2= new Group("c2feedme");
    System.out.println(g1.equals(g2));
    Group g3= new Group("c2feedme", "c2feedmo", "c2feedmy");
    System.out.println(g1.equals(g3));
    System.out.println(g3.equals(g1));
    System.out.println(g1.equals(null));
    System.out.println(g1.equals("Fred"));
  }
 }
