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
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,127 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