-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimals.java
More file actions
63 lines (48 loc) · 1.51 KB
/
Copy pathAnimals.java
File metadata and controls
63 lines (48 loc) · 1.51 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
public abstract class Animals {
private String name;
private int age;
private int weight;
private int jumpMax;
private int swimMax;
private int runMax;
Animals(String name, int age, int weight){
this.name=name;
this.age=age;
this.weight=weight;
jumpMax=SetJumpMax();
swimMax=SetSwimMax();
runMax=SetRunMax ();
}
public boolean Run (int runDistance){
boolean checkRun= CheckAction(runDistance,runMax,"пробежать");
return checkRun;
}
public boolean Jump (int height){
boolean checkRun= CheckAction(height,jumpMax,"перепрыгнуть");
return checkRun;
}
public boolean Swim (int swimDistance){
boolean checkRun= CheckAction(swimDistance,swimMax,"проплыть");
return checkRun;
}
private boolean CheckAction(int dist, int maxDist, String action){
if (dist<maxDist&&dist>0){
System.out.println(this.name + " может "+ action +" " + dist + " метров.");
return true;
}else {
System.out.println(this.name + " не может "+ action +" " + dist + " метров.");
} return false;
}
public String GetName(){
return this.name;
}
public int GetAge(){
return this.age;
}
public int GetWeight(){
return this.weight;
}
protected abstract int SetJumpMax();
protected abstract int SetRunMax();
protected abstract int SetSwimMax();
}