定义部件(Component)的重量(wight)概念,则其重量为本身重量加各子部件的重量之和,getWeight函数计算Component的重量,完成填空
public class Component {
private List <Component> children;
private int weight;
private int getWeight(){
int result = _________;
if(children != null){
for (Component child : children){
if(child != null){
result += ______________;
}
}
}
return result;
}
}