:">
public class Plant{
int height;
int value; //Selling price. Increases as plant grows
String type; //Type of Plant (ex. Apple, Banana, Carrot)
public Plant(){
type = "Generic Plant";
height = 0;
}
public Plant(int h){
height = h;
type = "Generic Plant";
}
public void grow(){
height = height + 10;
value = value + 100;
}
public void grow(int h){
height = height + h;
value = value + 10 * h;
}
public int getHeight(){
return height;
}
public int getValue(){
return value;
}
public String getType(){
return type;
}
}
public class FruitPlant extends Plant{
int numberOfFruit;
int fruitValue;
public FruitPlant(){
super();
type = "Generic Fruit Plant";
}
public void grow(){
super.grow();
numberOfFruit++;
}
public void grow(int i){
super.grow(i);
bearFruit();
}
public void bearFruit(){
numberOfFruit++;
}
public int harvestFruit(){
if(numberOfFruit>0){
numberOfFruit--;
return fruitValue;
} else {
return 0;
}
}
public int numberOfFruit(){
return numberOfFruit;
}
}
Post a Comment
Hi. :-h