Init
This commit is contained in:
commit
4e12cf549b
|
@ -0,0 +1,10 @@
|
|||
public class Barrier implements Obstacle{
|
||||
private int height;
|
||||
public Barrier(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public boolean passBy(Member member) {
|
||||
return member.jump(this.height);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
public class Course {
|
||||
private Obstacle[] obstacles;
|
||||
|
||||
public Course(Obstacle[] obstacles) {
|
||||
this.obstacles = obstacles;
|
||||
}
|
||||
|
||||
public void pass(Team team) {
|
||||
for(Member member: team.members) {
|
||||
boolean passed = true;
|
||||
for(Obstacle obstacle: this.obstacles) {
|
||||
if(!obstacle.passBy(member)) {
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
if(passed) {
|
||||
member.passDistance();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Obstacle[] obstacles = new Obstacle[] {
|
||||
new Barrier(20),
|
||||
new Barrier(50),
|
||||
new Barrier(40),
|
||||
new Pool(100),
|
||||
new Barrier(60),
|
||||
new Pool(150)
|
||||
};
|
||||
|
||||
Course course = new Course(obstacles);
|
||||
|
||||
Team team = new Team(
|
||||
new Member("Андрей", 160, 55),
|
||||
new Member("Борис", 90, 70),
|
||||
new Member("Василий", 200, 80),
|
||||
new Member("Геннадий", 170, 65)
|
||||
);
|
||||
team.showInfo();
|
||||
System.out.println();
|
||||
course.pass(team);
|
||||
team.showResults();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
public class Member {
|
||||
protected String name;
|
||||
private int swimDistance;
|
||||
private int jumpHeight;
|
||||
|
||||
protected boolean isDistancePassed;
|
||||
|
||||
public Member(String name, int swimDistance, int jumpHeight) {
|
||||
this.name = name;
|
||||
this.swimDistance = swimDistance;
|
||||
this.isDistancePassed = false;
|
||||
this.jumpHeight = jumpHeight;
|
||||
}
|
||||
|
||||
public void passDistance() {
|
||||
this.isDistancePassed = true;
|
||||
}
|
||||
|
||||
public boolean jump(int height) {
|
||||
return this.jumpHeight >= height;
|
||||
}
|
||||
|
||||
public boolean swim(int distance) {
|
||||
return this.swimDistance >= distance;
|
||||
}
|
||||
|
||||
|
||||
public void showInfo() {
|
||||
System.out.println("Имя: " + this.name +
|
||||
"\nДистанция плавания: " + this.swimDistance +
|
||||
"\nВысота прыжка: " + this.jumpHeight);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
public interface Obstacle {
|
||||
boolean passBy(Member member);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
public class Pool implements Obstacle {
|
||||
private int length;
|
||||
|
||||
public Pool(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public boolean passBy(Member member) {
|
||||
return member.swim(this.length);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
public class Team {
|
||||
protected Member[] members;
|
||||
|
||||
|
||||
public Team(Member member1, Member member2, Member member3, Member member4) {
|
||||
this.members = new Member[] {member1, member2, member3, member4};
|
||||
}
|
||||
|
||||
public void showInfo() {
|
||||
for(Member member: this.members) {
|
||||
member.showInfo();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void showResults() {
|
||||
System.out.println("Дистанцию прошли:");
|
||||
for(Member member: this.members) {
|
||||
if(member.isDistancePassed) {
|
||||
System.out.println(member.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue