From fba162e406a2083034687f658fc0bfe6bb84474e Mon Sep 17 00:00:00 2001 From: Mostafa Date: Sun, 14 Apr 2024 15:23:55 +0330 Subject: [PATCH] Quidditch Done! --- Answers/40230212083/Beater.java | 7 +++++++ Answers/40230212083/Chaser.java | 7 +++++++ Answers/40230212083/Keeper.java | 7 +++++++ Answers/40230212083/Match.java | 19 +++++++++++++++++++ Answers/40230212083/MyApp.java | 6 ++++++ Answers/40230212083/Player.java | 4 ++++ Answers/40230212083/Seeker.java | 7 +++++++ Answers/40230212083/Success.java | 3 +++ Answers/40230212083/Team.java | 26 ++++++++++++++++++++++++++ 9 files changed, 86 insertions(+) create mode 100644 Answers/40230212083/Beater.java create mode 100644 Answers/40230212083/Chaser.java create mode 100644 Answers/40230212083/Keeper.java create mode 100644 Answers/40230212083/Match.java create mode 100644 Answers/40230212083/MyApp.java create mode 100644 Answers/40230212083/Player.java create mode 100644 Answers/40230212083/Seeker.java create mode 100644 Answers/40230212083/Success.java create mode 100644 Answers/40230212083/Team.java diff --git a/Answers/40230212083/Beater.java b/Answers/40230212083/Beater.java new file mode 100644 index 0000000..171c521 --- /dev/null +++ b/Answers/40230212083/Beater.java @@ -0,0 +1,7 @@ +public class Beater extends Player implements Success{ + public boolean isSuccessful() { + int randNum = (int) (Math.random() * 101); + if(randNum<41) return true; + else return false; + } +} \ No newline at end of file diff --git a/Answers/40230212083/Chaser.java b/Answers/40230212083/Chaser.java new file mode 100644 index 0000000..d992238 --- /dev/null +++ b/Answers/40230212083/Chaser.java @@ -0,0 +1,7 @@ +public class Chaser extends Player implements Success{ + public boolean isSuccessful() { + int randNum = (int) (Math.random() * 101); + if(randNum<31) return true; + else return false; + } +} \ No newline at end of file diff --git a/Answers/40230212083/Keeper.java b/Answers/40230212083/Keeper.java new file mode 100644 index 0000000..4f9a696 --- /dev/null +++ b/Answers/40230212083/Keeper.java @@ -0,0 +1,7 @@ +public class Keeper extends Player implements Success{ + public boolean isSuccessful() { + int randNum = (int) (Math.random() * 101); + if(randNum<71) return true; + else return false; + } +} \ No newline at end of file diff --git a/Answers/40230212083/Match.java b/Answers/40230212083/Match.java new file mode 100644 index 0000000..ec7c58f --- /dev/null +++ b/Answers/40230212083/Match.java @@ -0,0 +1,19 @@ +public class Match{ + Team slytherin = new Team(); + Team gryffindor = new Team(); + public void start(){ + for(int i=0;i<100;i++){ + slytherin.play(); + gryffindor.play(); + } + System.out.println("Gryffindor Score: " + gryffindor.getScore()); + System.out.println("Slytherin Score: " + slytherin.getScore()); + if(slytherin.getScore() > gryffindor.getScore()) { + System.out.println("Slytherin Won !"); + }else if(slytherin.getScore() < gryffindor.getScore()){ + System.out.println("Gryffindor Won !"); + }else{ + System.out.println("Draw !"); + } + } +} \ No newline at end of file diff --git a/Answers/40230212083/MyApp.java b/Answers/40230212083/MyApp.java new file mode 100644 index 0000000..1e33c40 --- /dev/null +++ b/Answers/40230212083/MyApp.java @@ -0,0 +1,6 @@ +public class MyApp{ + public static void main(String[] args){ + Match game = new Match(); + game.start(); + } +} \ No newline at end of file diff --git a/Answers/40230212083/Player.java b/Answers/40230212083/Player.java new file mode 100644 index 0000000..4a3cfff --- /dev/null +++ b/Answers/40230212083/Player.java @@ -0,0 +1,4 @@ +public class Player{ + //What should we do here + //interface after function progarm ??? +} \ No newline at end of file diff --git a/Answers/40230212083/Seeker.java b/Answers/40230212083/Seeker.java new file mode 100644 index 0000000..a57a31b --- /dev/null +++ b/Answers/40230212083/Seeker.java @@ -0,0 +1,7 @@ +public class Seeker extends Player implements Success{ + public boolean isSuccessful() { + int randNum = (int) (Math.random() * 101); + if(randNum<6) return true; + else return false; + } +} \ No newline at end of file diff --git a/Answers/40230212083/Success.java b/Answers/40230212083/Success.java new file mode 100644 index 0000000..6371657 --- /dev/null +++ b/Answers/40230212083/Success.java @@ -0,0 +1,3 @@ +interface Success{ + public boolean isSuccessful(); +} \ No newline at end of file diff --git a/Answers/40230212083/Team.java b/Answers/40230212083/Team.java new file mode 100644 index 0000000..cd3ceaf --- /dev/null +++ b/Answers/40230212083/Team.java @@ -0,0 +1,26 @@ +public class Team{ + private int goalNum = 0; + Keeper ron = new Keeper(); + Chaser ginny1 = new Chaser(); + Chaser ginny2 = new Chaser(); + Chaser ginny3 = new Chaser(); + Beater george1 = new Beater(); + Beater george2 = new Beater(); + Seeker charlie = new Seeker(); + private void setGoal(){ + goalNum++; + } + void play(){ + //at least 2 chaser + int chaserChance = 0; + if(ginny1.isSuccessful()) chaserChance++; + if(ginny2.isSuccessful()) chaserChance++; + if(ginny3.isSuccessful()) chaserChance++; + // + if((chaserChance>1) && (george1.isSuccessful() || george2.isSuccessful()) && ron.isSuccessful()) goalNum++; + if(charlie.isSuccessful()) goalNum += 150; + } + public int getScore(){ + return goalNum; + } +} \ No newline at end of file