diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Quidditch.iml b/.idea/Quidditch.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Quidditch.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6f29fee --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ae8e6d9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/Program/Program.iml b/Answers/Program/Program.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Answers/Program/Program.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/Program/src/Beater.java b/Answers/Program/src/Beater.java new file mode 100644 index 0000000..3172d11 --- /dev/null +++ b/Answers/Program/src/Beater.java @@ -0,0 +1,11 @@ +class Beater extends Player { + public Beater(String name, int number) { + super(name, number); + } + + @Override + public boolean isSuccessful() { + // Beater has a 40% chance to stop chasers + return Math.random() < 0.4; + } +} // end class Beater \ No newline at end of file diff --git a/Answers/Program/src/Chaser.java b/Answers/Program/src/Chaser.java new file mode 100644 index 0000000..6589c03 --- /dev/null +++ b/Answers/Program/src/Chaser.java @@ -0,0 +1,11 @@ +class Chaser extends Player { + public Chaser(String name, int number) { + super(name, number); + } + + @Override + public boolean isSuccessful() { + // Chaser has a 30% chance to score a goal + return Math.random() < 0.3; + } +} // end class Chaser \ No newline at end of file diff --git a/Answers/Program/src/Keeper.java b/Answers/Program/src/Keeper.java new file mode 100644 index 0000000..357008b --- /dev/null +++ b/Answers/Program/src/Keeper.java @@ -0,0 +1,11 @@ +public class Keeper extends Player { + public Keeper(String name, int number) { + super(name, number); + } + + @Override + public boolean isSuccessful() { + // Keeper has a 70% chance to save a goal + return Math.random() < 0.7; + } +} // end class Keeper \ No newline at end of file diff --git a/Answers/Program/src/Match.java b/Answers/Program/src/Match.java new file mode 100644 index 0000000..425d5fc --- /dev/null +++ b/Answers/Program/src/Match.java @@ -0,0 +1,30 @@ +class Match { + private final Team team1; + private final Team team2; + + public Match(Team team1, Team team2) { + this.team1 = team1; + this.team2 = team2; + } + + public void start() { + for (int i = 0; i < 100; i++) { + team1.play(); + team2.play(); + } + + int team1Goals = team1.getGoals(); + int team2Goals = team2.getGoals(); + + System.out.println("Team 1 goals: " + team1Goals); + System.out.println("Team 2 goals: " + team2Goals); + + if (team1Goals == team2Goals) { + System.out.println("It's a draw!"); + } else if (team1Goals > team2Goals) { + System.out.println("Team 1 wins!"); + } else { + System.out.println("Team 2 wins!"); + } + } +} diff --git a/Answers/Program/src/MyApp.java b/Answers/Program/src/MyApp.java new file mode 100644 index 0000000..7867f97 --- /dev/null +++ b/Answers/Program/src/MyApp.java @@ -0,0 +1,25 @@ +public class MyApp { + public static void main(String[] args) { + // Creating players for team 1 + Keeper keeper1 = new Keeper("Keeper 1", 1); + Seeker seeker1 = new Seeker("Seeker 1", 2); + Chaser[] chasers1 = {new Chaser("Chaser 1", 3), new Chaser("Chaser 2", 4), + new Chaser("Chaser 3", 5)}; + Beater[] beaters1 = {new Beater("Beater 1", 6), + new Beater("Beater 2", 7)}; + Team team1 = new Team(keeper1, seeker1, chasers1, beaters1); + + // Creating players for team 2 + Keeper keeper2 = new Keeper("Keeper 2", 1); + Seeker seeker2 = new Seeker("Seeker 2", 2); + Chaser[] chasers2 = {new Chaser("Chaser 4", 3), new Chaser("Chaser 5", 4), + new Chaser("Chaser 6", 5)}; + Beater[] beaters2 = {new Beater("Beater 3", 6), + new Beater("Beater 4", 7)}; + Team team2 = new Team(keeper2, seeker2, chasers2, beaters2); + + // Starting the match + Match match = new Match(team1, team2); + match.start(); + } +} \ No newline at end of file diff --git a/Answers/Program/src/Player.java b/Answers/Program/src/Player.java new file mode 100644 index 0000000..a8601f8 --- /dev/null +++ b/Answers/Program/src/Player.java @@ -0,0 +1,17 @@ +interface Success { + boolean isSuccessful(); +} + +public class Player implements Success { + private final String name; + private final int number; + + public Player(String name, int number) { + this.name = name; + this.number = number; + } + + public boolean isSuccessful() { + return false; + } +} \ No newline at end of file diff --git a/Answers/Program/src/Seeker.java b/Answers/Program/src/Seeker.java new file mode 100644 index 0000000..ae6d908 --- /dev/null +++ b/Answers/Program/src/Seeker.java @@ -0,0 +1,11 @@ +class Seeker extends Player { + public Seeker(String name, int number) { + super(name, number); + } + + @Override + public boolean isSuccessful() { + // Seeker has a 5% chance to find the golden snitch + return Math.random() < 0.05; + } +} // end class Seeker \ No newline at end of file diff --git a/Answers/Program/src/Team.java b/Answers/Program/src/Team.java new file mode 100644 index 0000000..2fd2335 --- /dev/null +++ b/Answers/Program/src/Team.java @@ -0,0 +1,50 @@ +class Team { + private final Keeper keeper; + private final Seeker seeker; + private final Chaser[] chasers; + private final Beater[] beaters; + private int goals; + + public Team(Keeper keeper, Seeker seeker, Chaser[] chasers, Beater[] beaters) { + this.keeper = keeper; + this.seeker = seeker; + this.chasers = chasers; + this.beaters = beaters; + this.goals = 0; + } + + private void setGoal() { + goals++; + } + + public void play() { + boolean keeperSuccess = keeper.isSuccessful(); + int successfulBeaters = 0; + int successfulChasers = 0; + + for (Beater beater : beaters) { + if (beater.isSuccessful()) { + successfulBeaters++; + } + } + + for (Chaser chaser : chasers) { + if (chaser.isSuccessful()) { + successfulChasers++; + } + } + + if (keeperSuccess && successfulBeaters >= 1 && successfulChasers >= 2) { + setGoal(); + } + + if (seeker.isSuccessful()) { + System.out.println("Seeker found the golden snitch!"); + goals += 150; + } + } + + public int getGoals() { + return goals; + } +} \ No newline at end of file diff --git a/out/production/Program/Beater.class b/out/production/Program/Beater.class new file mode 100644 index 0000000..0842ef8 Binary files /dev/null and b/out/production/Program/Beater.class differ diff --git a/out/production/Program/Chaser.class b/out/production/Program/Chaser.class new file mode 100644 index 0000000..e447fd3 Binary files /dev/null and b/out/production/Program/Chaser.class differ diff --git a/out/production/Program/Keeper.class b/out/production/Program/Keeper.class new file mode 100644 index 0000000..e45d488 Binary files /dev/null and b/out/production/Program/Keeper.class differ diff --git a/out/production/Program/Match.class b/out/production/Program/Match.class new file mode 100644 index 0000000..3c17658 Binary files /dev/null and b/out/production/Program/Match.class differ diff --git a/out/production/Program/MyApp.class b/out/production/Program/MyApp.class new file mode 100644 index 0000000..c8bd2df Binary files /dev/null and b/out/production/Program/MyApp.class differ diff --git a/out/production/Program/Player.class b/out/production/Program/Player.class new file mode 100644 index 0000000..f6bbe3d Binary files /dev/null and b/out/production/Program/Player.class differ diff --git a/out/production/Program/Seeker.class b/out/production/Program/Seeker.class new file mode 100644 index 0000000..900093e Binary files /dev/null and b/out/production/Program/Seeker.class differ diff --git a/out/production/Program/Success.class b/out/production/Program/Success.class new file mode 100644 index 0000000..1fdd090 Binary files /dev/null and b/out/production/Program/Success.class differ diff --git a/out/production/Program/Team.class b/out/production/Program/Team.class new file mode 100644 index 0000000..08377bb Binary files /dev/null and b/out/production/Program/Team.class differ