Question: Class Forest: import java.util.ArrayList; import java.util.Arrays; public class Forest { String name; String location; double squareMetre; String natureofTrees; int price; Owner forestOwner; Tree t; double
Class Forest:
import java.util.ArrayList;
import java.util.Arrays;
public class Forest {
String name;
String location;
double squareMetre;
String natureofTrees;
int price;
Owner forestOwner;
Tree t;
double forestRevenue=0;
private ArrayList
public Forest(){
TreeList= new ArrayList
}
public void add(Tree costs){
TreeList.add(costs);
}
public double getForestRevenue(){
for (Tree revenuelist:TreeList){
forestRevenue+=revenuelist.getCost();
}
return forestRevenue;
}
public double ForestProfit(){
return forestRevenue-t.cost;
}
public double getCost(){
return t.getCost();
}
public Forest(String name, String location, double squareMeter, String natureofTrees, int price ) {
this.name = name;
this.location = location;
this.squareMetre = squareMeter;
this.natureofTrees = natureofTrees;
this.price = price;
}
public Tree getT() {
return t;
}
public void setT(Tree t) {
this.t = t;
}
public Owner getForestOwner() {
return forestOwner;
}
public void setForestOwner(Owner forestOwner) {
this.forestOwner = forestOwner;
}
public String Tree(String t){
return t;
}
public Forest(Owner forestOwner ){
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public double getSquareMetre() {
return squareMetre;
}
public void setSquareMetre(double squareMeter) {
this.squareMetre = squareMeter;
}
public String getNatureofTrees() {
return natureofTrees;
}
public void setNatureofTrees(String natureofTrees) {
this.natureofTrees = natureofTrees;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
@Override
public String toString() {
return "Forest{" + "Name=" + name + ", Location=" + location + ", Size of forest=" + squareMetre + ", Kind of tree=" + natureofTrees + ", Price=" + price +'}';
}
}
class Tree:
public class Tree {
String sort;
String lifespan;
double cost;
int revenue;
@Override
public String toString() {
return "Tree{" + "Sort=" + sort + ", Lifespan=" + lifespan + ", Cost per square km=" + cost + '}';
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String getLifespan() {
return lifespan;
}
public void setLifespan(String lifespan) {
this.lifespan = lifespan;
}
public double getCost() {
return cost;
}
public void setCost(double cost) {
this.cost = cost;
}
public int getRevenue() {
return revenue;
}
public void setRevenue(int revenue) {
this.revenue = revenue;
}
public Tree(String sort, String lifespan, double cost) {
this.sort = sort;
this.lifespan = lifespan;
this.cost = cost;
this.revenue = revenue;
}
}
class Owner:
public class Owner {
String ownername;
String address;
int phonenumber;
public Owner(String ownername, String address, int phonenumber) {
this.ownername = ownername;
this.address = address;
this.phonenumber = phonenumber;
}
@Override
public String toString() {
return "Owner{" + "Owner Name=" + ownername + ", Address=" + address + ", Phone Number=" + phonenumber + '}';
}
public String getOwnername() {
return ownername;
}
public void setOwnername(String ownername) {
this.ownername = ownername;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(int phonenumber) {
this.phonenumber = phonenumber;
}
}
-----------------------------------------------------------------------------
Q.Answers following points

Association between the Classes 16, Add a mutatormethod to the Forest class that adds a tree object to the class 17. Update the print method from the forest class in such a wav that if a tree obiect is associated, this information is printed as well 18. Add anaccessor method for the forest class that returns the cost of the forest. (hint: data must be fetched from another class) 19. Add an accessor method for the forest class that calculates the revenue of the forest. 20. Add a method that calculated the profit of the forest (revenue - cost)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
