I'm about a month into my BSc in Software, and we are working on this forest project where we have different type of trees (ashes and beeches) which grows in different pace. They are subclasses to the general class Tree.
My problem is now I'm asked to add two trees of each kind of tree (ash and beech) to an ArrayList – their int age and double height should all be different. I simply can't put my head around how this should be set up so any advices/hints/solutions is greatly appreciated.
Source for Tree
public class Tree{
public int age;
public double height;
public void growOneYear()
{
age++;
}
public void show()
{
System.out.println("Træet er " +age+ " år gammelt og " +height+ " meter højt.");
}
}
Source for Ash (almost identical to Beech)
public class Ash extends Tree {
public Ash()
{
age = 1;
height = 1.0;
}
public void growOneYear()
{
super.growOneYear();
if(height < 15){
height = height*1.20;
}
}
public void show()
{
System.out.println("Ask: ");
super.show();
}
}