Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures Efficiency! Using a Map to store Contact Methods

Javier MARQUEZ
Javier MARQUEZ
11,877 Points

Thanks for your help on the 3rd stage of this challenge.

Thanks for your help on the 3rd stage of this challenge.

com/example/model/Contact.java
package com.example.model;

import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import java.util.*;

public class Contact {
  private String mFirstName;
  private String mLastName;
  private Map<String, String> mContactMethods;

  public Contact(String firstName, String lastName) {
    mFirstName = firstName;
    mLastName = lastName;
    /* This stores contact methods by name
     * eg:  "phone" => "(555) 555-1234"
     */
    mContactMethods = new HashMap<String, String>();
  }

  public void addContactMethod(String method, String value) {
    mContactMethods.put(method, value);
  }

  /**
   * Returns the available contact methods.  eg: phone, pager,
   *
   * @return The name of the contact methods that are available
   */
  public Set<String> getAvailableContactMethods() {
    // getAvailableContactMethods method. We want to return a set of the currently defined contact methods.
    Set<String> results = new HashSet<String>(mContactMethods.keySet());     
    return results;
  }

  /**
   * Returns the value for the contact method if it exists, 
   *
   * @param methodName  The name of the contact method to look up.
   * @return The name of the contact methods that are available
   */
  public String getContactInfo(Contact chosenContact, String methodName) {
    String results = chosenContact.mContactMethods.get(methodName);
    return null;
  }

  public String getFirstName() {
    return mFirstName;
  }

  public String getLastName() {
    return mLastName;
  }

}

2 Answers

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

Scroll through community answers for help by clicking on 'Using a Map to store Contact Methods' on the top of the page, above the title of your question:

Java -> Java Data Structures -> Efficiency! -> Using a Map to store Contact Methods

Here is direct link:

https://teamtreehouse.com/community/code-challenge:7812

Sometimes also checking question section to the video before the question is very helpful.

Here is good one form that list:

https://teamtreehouse.com/community/stuck-on-java-data-structures-using-a-map-to-store-contact-methods-task-3-of-3

Javier MARQUEZ
Javier MARQUEZ
11,877 Points

Thanks a lot, my question was covered