-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForestAnimal.java
More file actions
59 lines (48 loc) · 1.25 KB
/
ForestAnimal.java
File metadata and controls
59 lines (48 loc) · 1.25 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
package Question11;
public class ForestAnimal {
private String name;
private int speech;
private boolean flyable;
protected ForestAnimal(Builder builder){
this.name = builder.name;
this.speech= builder.speech;
this.flyable = builder.flyable;
}
public String getName() {
return name;
}
public int getSpeech() {
return speech;
}
public boolean isFlyable() {
return flyable;
}
@Override
public String toString() {
return "ForestAnimal{" +
"name='" + name + '\'' +
", speech=" + speech +
", flyable=" + flyable +
'}';
}
public static class Builder{
private String name;
private int speech;
private boolean flyable;
public Builder setName(String name) {
this.name = name;
return this;
}
public Builder setSpeech(int speech) {
this.speech = speech;
return this;
}
public Builder setFlyable(boolean flyable) {
this.flyable = flyable;
return this;
}
public ForestAnimal build(){
return new ForestAnimal(this);
}
}
}