gb-java-devel/src/s03-hw2-animal.java

50 lines
1.2 KiB
Java
Raw Normal View History

2022-12-30 09:52:59 +03:00
package ru.gb.jcore.marathon;
import java.util.Random;
public abstract class Animal {
static final int SWIM_FAIL = 0;
static final int SWIM_OK = 1;
static final int SWIM_WTF = -1;
private String type;
private String name;
private float maxRun;
private float maxSwim;
private float maxJump;
private final Random random = new Random();
Animal(String type, String name, float maxJump, float maxRun, float maxSwim) {
this.type = type;
this.name = name;
this.maxJump = maxJump;
this.maxRun = maxRun;
this.maxSwim = maxSwim;
}
String getName() {
return this.name;
}
String getType() {
return this.type;
}
float getMaxRun() {
return this.maxRun;
}
float getMaxSwim() {
return this.maxSwim;
}
float getMaxJump() {
return this.maxJump;
}
protected boolean run(float distance) {
return (distance <= maxRun);
}
protected int swim(float distance) {
return (distance <= maxSwim) ? SWIM_OK : SWIM_FAIL;
}
protected boolean jump(float height) {
return (height <= maxJump);
}
}