-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.java
More file actions
70 lines (61 loc) · 1.61 KB
/
Copy pathTree.java
File metadata and controls
70 lines (61 loc) · 1.61 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.Random;
public class Tree {
public int age;
public Leaf x1 = new Leaf();
public Leaf x2 = new Leaf();
public Leaf x3 = new Leaf();
public void Tree(int a,Leaf b,Leaf c,Leaf d){
this.age = a;
this.x1 = b;
this.x2 = c;
this.x3 = d;
}
//初始化一棵树,需要给出树叶的最大以及平均值,树叶的值随机获取
public Tree initTree(double max1,double avg1,double max2,double avg2,double avg3,double max3){
Tree result = new Tree();
Leaf b = new Leaf();
b.setMax(max1);
b.setAvg(avg1);
Leaf c = new Leaf();
c.setMax(max2);
c.setAvg(avg2);
Leaf d = new Leaf();
d.setMax(max3);
d.setAvg(avg3);
double rb = (double)(Math.random()*b.max);
double rc = (double)(Math.random()*c.max);
double rd = (double)(Math.random()*d.max);
b.setVal(rb);
c.setVal(rc);
d.setVal(rd);
result.setX1(b);
result.setX2(c);
result.setX3(d);
result.setAge(0);
return result;
}
public void setAge(int age) {
this.age = age;
}
public void setX1(Leaf x1) {
this.x1 = x1;
}
public void setX2(Leaf x2) {
this.x2 = x2;
}
public void setX3(Leaf x3) {
this.x3 = x3;
}
public int getAge() {
return age;
}
public Leaf getX1() {
return x1;
}
public Leaf getX2() {
return x2;
}
public Leaf getX3() {
return x3;
}
}