commit 4e12cf549b4b29adef4151d52a87f8220777ffa0 Author: nefrace Date: Sat May 14 23:08:44 2022 +0300 Init diff --git a/src/Barrier.java b/src/Barrier.java new file mode 100644 index 0000000..0a44a32 --- /dev/null +++ b/src/Barrier.java @@ -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); + } +} diff --git a/src/Course.java b/src/Course.java new file mode 100644 index 0000000..613e6a4 --- /dev/null +++ b/src/Course.java @@ -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(); + } + } + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..22b18d5 --- /dev/null +++ b/src/Main.java @@ -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(); + } +} diff --git a/src/Member.java b/src/Member.java new file mode 100644 index 0000000..9a87ed9 --- /dev/null +++ b/src/Member.java @@ -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); + } +} diff --git a/src/Obstacle.java b/src/Obstacle.java new file mode 100644 index 0000000..c11f4eb --- /dev/null +++ b/src/Obstacle.java @@ -0,0 +1,3 @@ +public interface Obstacle { + boolean passBy(Member member); +} diff --git a/src/Pool.java b/src/Pool.java new file mode 100644 index 0000000..7348f6a --- /dev/null +++ b/src/Pool.java @@ -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); + } +} diff --git a/src/Team.java b/src/Team.java new file mode 100644 index 0000000..b670435 --- /dev/null +++ b/src/Team.java @@ -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); + } + } + } +}