From a8d8e705b0ac62f5e4a434e29f57d86aab6907f5 Mon Sep 17 00:00:00 2001 From: Raziyeh Date: Sun, 14 Apr 2024 22:48:42 +0000 Subject: [PATCH] Quidditch Game --- Answers/40230112005/Beater.java | 9 ++++++++ Answers/40230112005/Chaser.java | 9 ++++++++ Answers/40230112005/Keeper.java | 9 ++++++++ Answers/40230112005/Match.java | 19 +++++++++++++++++ Answers/40230112005/Myapp.java | 6 ++++++ Answers/40230112005/Player.java | 3 +++ Answers/40230112005/Seeker.java | 9 ++++++++ Answers/40230112005/Success.java | 3 +++ Answers/40230112005/Team.java | 36 ++++++++++++++++++++++++++++++++ 9 files changed, 103 insertions(+) create mode 100644 Answers/40230112005/Beater.java create mode 100644 Answers/40230112005/Chaser.java create mode 100644 Answers/40230112005/Keeper.java create mode 100644 Answers/40230112005/Match.java create mode 100644 Answers/40230112005/Myapp.java create mode 100644 Answers/40230112005/Player.java create mode 100644 Answers/40230112005/Seeker.java create mode 100644 Answers/40230112005/Success.java create mode 100644 Answers/40230112005/Team.java diff --git a/Answers/40230112005/Beater.java b/Answers/40230112005/Beater.java new file mode 100644 index 0000000..4ece10b --- /dev/null +++ b/Answers/40230112005/Beater.java @@ -0,0 +1,9 @@ +public class Beater extends Player implements Success{ + public boolean isSuccessful(){ + int rand=(int)(Math.random()*101); + if(rand<41){ + return true; + } + return false; + } +} \ No newline at end of file diff --git a/Answers/40230112005/Chaser.java b/Answers/40230112005/Chaser.java new file mode 100644 index 0000000..35df572 --- /dev/null +++ b/Answers/40230112005/Chaser.java @@ -0,0 +1,9 @@ +public class Chaser extends Player implements Success{ + public boolean isSuccessful() { + int rand = (int) (Math.random() * 101); + if(rand<31){ + return true; + } + return false; + } +} \ No newline at end of file diff --git a/Answers/40230112005/Keeper.java b/Answers/40230112005/Keeper.java new file mode 100644 index 0000000..f7fdef1 --- /dev/null +++ b/Answers/40230112005/Keeper.java @@ -0,0 +1,9 @@ +public class Keeper extends Player implements Success{ + public boolean isSuccessful() { + int rand = (int) (Math.random() * 101); + if(rand<71){ + return true; + } + return false; + } +} \ No newline at end of file diff --git a/Answers/40230112005/Match.java b/Answers/40230112005/Match.java new file mode 100644 index 0000000..25c3e0b --- /dev/null +++ b/Answers/40230112005/Match.java @@ -0,0 +1,19 @@ +public class Match { + Team team1=new Team(); + Team team2=new Team(); + public void start(){ + for(int i=0 ; i<100 ; i++){ + team1.Play(); + team2.Play(); + } + System.out.println("Team1 Score: " + team1.score()); + System.out.println("Team2 Score: " + team2.score()); + if(team2.score() > team1.score()){ + System.out.println("Team2 Won!"); + }else if(team2.score() < team1.score()) { + System.out.println("Team1 Won!"); + }else{ + System.out.println("Draw!"); + } + } +} \ No newline at end of file diff --git a/Answers/40230112005/Myapp.java b/Answers/40230112005/Myapp.java new file mode 100644 index 0000000..70efc50 --- /dev/null +++ b/Answers/40230112005/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/40230112005/Player.java b/Answers/40230112005/Player.java new file mode 100644 index 0000000..cd118f1 --- /dev/null +++ b/Answers/40230112005/Player.java @@ -0,0 +1,3 @@ +public class Player { + +} \ No newline at end of file diff --git a/Answers/40230112005/Seeker.java b/Answers/40230112005/Seeker.java new file mode 100644 index 0000000..8b2bbe3 --- /dev/null +++ b/Answers/40230112005/Seeker.java @@ -0,0 +1,9 @@ +public class Seeker extends Player implements Success{ + public boolean isSuccessful() { + int rand = (int) (Math.random() * 101); + if(rand<6){ + return true; + } + return false; + } +} \ No newline at end of file diff --git a/Answers/40230112005/Success.java b/Answers/40230112005/Success.java new file mode 100644 index 0000000..6371657 --- /dev/null +++ b/Answers/40230112005/Success.java @@ -0,0 +1,3 @@ +interface Success{ + public boolean isSuccessful(); +} \ No newline at end of file diff --git a/Answers/40230112005/Team.java b/Answers/40230112005/Team.java new file mode 100644 index 0000000..a728305 --- /dev/null +++ b/Answers/40230112005/Team.java @@ -0,0 +1,36 @@ +public class Team { + private int goal=0; + Keeper keeper1= new Keeper(); + Chaser chaser1=new Chaser(); + Chaser chaser2=new Chaser(); + Chaser chaser3=new Chaser(); + Beater beater1=new Beater(); + Beater beater2=new Beater(); + Seeker seeker1=new Seeker(); + + private void setGoal(){ + goal++; + } + + void Play() { + int chasercounter = 0; + if (chaser1.isSuccessful()) { + chasercounter++; + } + if (chaser2.isSuccessful()) { + chasercounter++; + } + if (chaser3.isSuccessful()) { + chasercounter++; + } + if (chasercounter > 1 && (beater1.isSuccessful() || beater2.isSuccessful()) && keeper1.isSuccessful()) { + goal++; + } + if (seeker1.isSuccessful()) { + goal += 150; + } + } + public int score(){ + return goal; + } +} \ No newline at end of file