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 trialJavier MARQUEZ
11,877 PointsThanks for your help on the 3rd stage of this challenge.
Thanks for your help on the 3rd stage of this challenge.
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
Java Web Development Techdegree Graduate 22,175 PointsScroll 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:
Javier MARQUEZ
11,877 PointsThanks a lot, my question was covered