0
這是我到目前爲止,什麼即時嘗試做我不知道如何訪問兩部分拆分這段代碼是真的錯了,但我不知道如何做我想要的東西(是的,它是學校)地圖錯誤與功能
public class Relatives
{
private Map<String,Set<String>> map;
/**
* Constructs a relatives object with an empty map
*/
public Relatives()
{
map = new TreeMap<String,Set<String>>();
}
/**
* adds a relationship to the map by either adding a relative to the
* set of an existing key, or creating a new key within the map
* @param line a string containing the key person and their relative
*/
public void setPersonRelative(String line)
{
String[] personRelative = line.split(" ");
if(map.containsKey(personRelative[0]))
{
map.put(personRelative[0],map.get(personRelative[1])+personRelative[1]);
}
else
{
map.put(personRelative[0],personRelative[1]);
}
}
我嘗試訪問的人,並加入到有電流的親戚,如果不要存在創建一個新的人與相對
所以返回這樣
如何將我格式化Dot is related to Chuck Fred Jason Tom
Elton is related to Linh
我有這個,但得到錯誤
public String getRelatives(String person)
{
return map.keySet();
}