I am writing a toString method for my Nursery class but am having trouble getting everything working properly. I have to go through the ArrayList and call the toString method for each individual tree and then the sum for all of the trees prices. Here is what I got so far.
public String toString() {
int sum = 0;
Iterator i = treeList.iterator();
while(i.hasNext()) {
Tree iTree = (Tree) i.next();
sum += iTree.getTreePrice();
}
return iTree.toString() + "The sum of the whole collection is $" + sum + ".";
}
This doesn't work, but its just what I could bang out so far. Thanx in advance.