This commit is contained in:
nefrace 2022-05-14 23:08:44 +03:00
commit 4e12cf549b
7 changed files with 127 additions and 0 deletions

10
src/Barrier.java Normal file
View File

@ -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);
}
}

21
src/Course.java Normal file
View File

@ -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();
}
}
}
}

25
src/Main.java Normal file
View File

@ -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();
}
}

33
src/Member.java Normal file
View File

@ -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);
}
}

3
src/Obstacle.java Normal file
View File

@ -0,0 +1,3 @@
public interface Obstacle {
boolean passBy(Member member);
}

11
src/Pool.java Normal file
View File

@ -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);
}
}

24
src/Team.java Normal file
View File

@ -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);
}
}
}
}