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 trialGabriel E
8,916 PointsHow do I fix the getAvailableContacts method?
Hi there,
I'm working on challenge task 2 of 3, and I'm trying to get through this code in the getAvailableContacts method. Do you have any suggestions?
Thanks!
package com.example.model;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
public class Contact {
private String mFirstName;
private String mLastName;
private Map<String, String> mContactMethods;
public Contact(String firstName, String lastName) {
mFirstName = firstName;
mLastName = lastName;
mContactMethods = new HashMap<String, String>();
}
public void addContactMethod(String method, String value) {
mContactMethods.put(method, value);
}
public Set<String> getAvailableContactMethods() {
private Map<String, String> mContactMethods;
}
public String getContactInfo(String methodName) {
return null;
}
public String getFirstName() {
return mFirstName;
}
public String getLastName() {
return mLastName;
}
}
2 Answers
piyush arora
5,735 PointsHi Gabriel,
To get all the contact methods you just need to add mContactNames.keySet() in getAvailableContactMethods(). mContactNames contains method-value pairings. To get the keys in a map you use the inbuilt interface keySet that returns a set of keys in the map.
Sérgio Haruo Hattori
5,867 PointsCheck the post from Brody Ricketts at this URL :
He explains really well what you should do (and not giving the answer directly, which is better.
Brody Ricketts
15,612 PointsI feel like I have accomplished something in my life to know that my name is being linked to something I have done in order to help other people. Thank you Sérgio Haruo Hattori
Mridul Gupta
2,144 PointsMridul Gupta
2,144 PointsRefer to the below code for help. The answers to your questions are in the video itself. :) I would say go through the video again whenever you get stuck on a challenge and you will find your answer. :-)