I have an array list that could contain component or composite and each component or composite has a tax field that i would like to get the value.The purpose of this method is to get the total tax due by all the components and composites in the array list.A component can also contain a composite .The problem is when a component contains a composite ,My method does not get the value in the composite
ArrayList allprinceSubjects = new ArrayList();
public double calculateTaxDueByComponents(){
double totaltaxdue=0;
Iterator iterator = vassalsanddukes.iterator();
while(iterator.hasNext()){
RiruritaniaSubjects vassalandduke=(RiruritaniaSubjects) iterator.next();
totaltaxdue+=vassalandduke.getTaxDue();
vassalandduke.calculateTaxDueByComponents();
}
return totaltaxdue;
}
Not sure how your business logic are implemented, but I think the following line needs changing:
Change it to: