Professional Documents
Culture Documents
{
private String name;
private String type;
private boolean evergreen;
private double height;
private boolean fruitful;
public Tree (String xname,String xtype,boolean xevergreen,double xheight,boolean
xfruitful)
{
name=xname;
type=xtype;
evergreen=xevergreen;
height=xheight;
fruitful=xfruitful;
}
public String getname()
{
return name;
}
public String gettype()
{
return type;
}
public boolean getevergreen()
{
return evergreen;
}
public double getheight()
{
return height;
}
public boolean getfruitful()
{
return fruitful;
}
public void setname(String xname)
{
name=xname;
}
return true;
else{
return false;
}
}}
import java.util.*;
public class Forest
{
private String name;
private String county ;
private ArrayList<Tree> trees;
public Forest (String xname,String xcounty)
{
name=xname;
county=xcounty;
trees=new ArrayList<Tree>();
}
public String getname()
{
return name;
}
public String getcounty()
{
return county;
}
public ArrayList<Tree> gettrees()
{
return trees;
}
public void setname(String xname)
{
name=xname;
}
public void setcounty(String xcounty)
{
county=xcounty;
}
public void settreres(ArrayList<Tree> xtrees)
{
trees=xtrees;
}
public void AddTree(Tree T)
{
trees.add(T) ;
}
public void FindTree(Tree T)
{
if(trees.contains(T))
{
T.print();
}
else
{
System.out.println(" An "+T.getname()+ "tree is not found in the
forest");
}
}
public void RemoveFruitfulTrees()
{
Iterator<Tree> itr= trees.iterator();
while(itr.hasNext())
{
Tree s=itr.next();
if(s.getfruitful()){
trees.remove(s);
}