publicvoidaddChild(){Personp=database.get(selectedName);if(p==null){UI.println("Nooneiscalled"+p);return;}StringselectedName=capitalise(UI.askString("Nameofchildof"+selec...
public void addChild(){
Person p = database.get(selectedName);
if(p==null){
UI.println("No one is called " + p);
return;
}
String selectedName = capitalise(UI.askString("Name of child of"+selectedName));
if(p.getChildren().contains(selectedName)){
UI.println(p+"is already a child of"+selectedName);
}
else{
p.addChild(selectedName);
}
if(!database.containsKey(selectedName)){
if(UI.askBoolean("Add"+selectedName+"to the database?")){
Person child = askPerson(); //这个括号里面应该写什么,只要这一个,其他的先不用管。
if(!selectedName.equals(child.getFather())&&(child.getMother())){
UI.println(child+"must have"+selectedName+"as a parent");
}
else{
database.put(selectedName);
UI.println("Added:"+selectedName);
}
}
}
UI.println("-----------------");
}
展开