-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrove.java
More file actions
35 lines (31 loc) · 736 Bytes
/
Grove.java
File metadata and controls
35 lines (31 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class Grove {
public String groveName;
public Tree trees[];
public Grove(String groveName){
this.trees=new Tree[16];
this.groveName=groveName;
}
public int plant(Tree tree){
for (int i=0; i<trees.length; i++){
if (trees[i]==null){
trees[i]= tree;
return i;
}
}
return -1;
}
public Tree remove(int num){
Tree oldTree=trees[num];
trees[num]=null;
return oldTree;
}
public String toString(){
int count=0;
for (int i=0;i<trees.length;i++){
if (trees[i]!=null){
count+=1;
}
}
return ""+count;
}
}