{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

SubRegion - if(constituents.get(k instanceof SubRegion...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//SubRegion import java.util.Vector; public class SubRegion extends Region{ private Vector<Region> constituents=null;//makes a null vector public SubRegion(String s, int a, Vector<Region> r){ super(s,a); constituents=r; } public int getPopulation(){ int pop=0; int length=constituents.size(); if(constituents==null){ return 0; } else if(length==0){ return 0; } else for(int k=0;k<length;k++){
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if(constituents.get(k) instanceof SubRegion){ SubRegion s=(SubRegion)constituents.get(k); pop=pop+s.getPopulation(); } if(constituents.get(k) instanceof Town){ Town t=(Town)constituents.get(k); pop=pop+t.getPopulation(); } } return pop; } public String toString(){ return super.toString()+" and has population "+this.getPopulation(); } }...
View Full Document

{[ snackBarMessage ]}