我在这个学校实验室工作,我的 toString 有问题,这就是我所拥有的
public String getRelatives(String person)
{
String s = "";
s+=(person);
s+=(" is related to ");
for(String relative : map.get(person))
{
s+=(relative);
s+=(' ');
}
return s;
}
/**
* returns the String version of the entire map listing each key person and all of
* their relatives
*/
public String toString()
{
String output="";
return getRelatives();
}
我也希望它看起来像这样
Bob is related to John Tom
Dot is related to Chuck Fred Jason Tom
Elton is related to Linh
我知道我在我的 toString 中做错了,但至少对我来说这是有道理的,我不确定我应该怎么做