build a hybrid tree of fruits
Ok so I have these interfaces and classes:
Code:
interface Tree extends Cloneable { int size(); }
class Fruit implements Tree {
@Override public int size() {
return this.size();
}
}
class Branch implements Tree {
private List<Tree> children = new LinkedList<Tree>();
public List<Tree> getChildren() { return Collections.unmodifiableList(children); }
public void addChild(Tree tree) { children.add(tree); }
@Override public int size() {
int size = 0;
for(Tree tree: children) size += tree.size();
return size;
}
}
class Mango extends Fruit { /* intentionally left empty */ }
class Peach extends Fruit { /* intentionally left empty */ }
And I need to create code that structures this type of hybrid tree:
the trunk (main branch) of the tree
a branch with two mangoes
another branch with
a (sub)branch with two mangoes
I got the first part:
Branch trunk = new Branch();
But not sure how to code the next parts, can anyone help me with this?