From b0dadd0a60a1d90a3e205193f2db5bd907080b6e Mon Sep 17 00:00:00 2001 From: "Amir.Homa" Date: Sat, 13 Apr 2024 20:48:31 +0330 Subject: [PATCH 1/3] add number of team classes --- .idea/Quidditch.iml | 9 ++ .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 45 +++++++ Answers/_40230112134/.gitignore | 38 ++++++ Answers/_40230112134/.idea/.gitignore | 3 + Answers/_40230112134/.idea/encodings.xml | 7 + Answers/_40230112134/.idea/misc.xml | 14 ++ Answers/_40230112134/.idea/uiDesigner.xml | 124 ++++++++++++++++++ Answers/_40230112134/.idea/vcs.xml | 6 + Answers/_40230112134/How to send.txt | 3 + Answers/_40230112134/README.md | 46 +++++++ Answers/_40230112134/pom.xml | 17 +++ .../src/main/java/org/example/Main.java | 6 + .../src/main/java/org/example/Player.java | 107 +++++++++++++++ .../src/main/java/org/example/Success.java | 5 + 17 files changed, 450 insertions(+) create mode 100644 .idea/Quidditch.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 Answers/_40230112134/.gitignore create mode 100644 Answers/_40230112134/.idea/.gitignore create mode 100644 Answers/_40230112134/.idea/encodings.xml create mode 100644 Answers/_40230112134/.idea/misc.xml create mode 100644 Answers/_40230112134/.idea/uiDesigner.xml create mode 100644 Answers/_40230112134/.idea/vcs.xml create mode 100644 Answers/_40230112134/How to send.txt create mode 100644 Answers/_40230112134/README.md create mode 100644 Answers/_40230112134/pom.xml create mode 100644 Answers/_40230112134/src/main/java/org/example/Main.java create mode 100644 Answers/_40230112134/src/main/java/org/example/Player.java create mode 100644 Answers/_40230112134/src/main/java/org/example/Success.java 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..07115cd --- /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..ee6a3c5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ 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/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..89a7b1a --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + 1712772973807 + + + + \ No newline at end of file diff --git a/Answers/_40230112134/.gitignore b/Answers/_40230112134/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/Answers/_40230112134/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Answers/_40230112134/.idea/.gitignore b/Answers/_40230112134/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Answers/_40230112134/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Answers/_40230112134/.idea/encodings.xml b/Answers/_40230112134/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/Answers/_40230112134/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Answers/_40230112134/.idea/misc.xml b/Answers/_40230112134/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/Answers/_40230112134/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Answers/_40230112134/.idea/uiDesigner.xml b/Answers/_40230112134/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/Answers/_40230112134/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/_40230112134/.idea/vcs.xml b/Answers/_40230112134/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/Answers/_40230112134/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/_40230112134/How to send.txt b/Answers/_40230112134/How to send.txt new file mode 100644 index 0000000..3ad8fad --- /dev/null +++ b/Answers/_40230112134/How to send.txt @@ -0,0 +1,3 @@ +bring your project in this folder +commit each changes of your project. +at the end, send a pull request to orginal repo. \ No newline at end of file diff --git a/Answers/_40230112134/README.md b/Answers/_40230112134/README.md new file mode 100644 index 0000000..ea11fad --- /dev/null +++ b/Answers/_40230112134/README.md @@ -0,0 +1,46 @@ +# Quidditch +In this assignment, we will delve into Object-Oriented Programming (OOP) with a simple but appealing mini project. This mini project would be very enjoyable for Harry Potter fans, but if you haven't watched the film, don't worry; you don't need any pre-knowledge about this film to do this assignment. You can also use [this link](https://gustavus.edu/im/Spring/quidditch-rules.php#:~:text=Neither%20seekers%20nor%20snitched%20are,their%20broomstick%20at%20all%20times.) to read about Quidditch rules. + +## What Should I Do +Your assignment is a bit different from the real game. You won't need to implement any GUI or complex logic; the whole logic will be handled by chance. Don't worry! + +We have two teams. Each team has a keeper, a seeker, 3 chasers, and 2 beaters. You can read about each role's responsibilities in the above link, so let's talk about implementing the project. Each of these roles has a name, number, and each one has a method called `isSuccessful`. The chance of success varies for each one. Let's start with the keeper. + +### Keeper +The keeper has a 70% chance to save a hanging goal. + +### Seeker +The seeker has a 5% chance to find the golden snitch. + +### Chaser +The chaser has a 30% chance to score a goal. + +### Beater +The beater has a 40% chance to stop chasers. + +## How to Implement + +### Classes +- Create a class for each role (Keeper, Seeker, etc.). +- Create a class called `Player` and make all roles inherit this class. +- Create an interface called `Success` and put the method `isSuccessful` inside it. Don't forget to implement this interface with all of your roles. What's next? + +#### Team +- Create a class for `Team`. This class contains players of your team (1 Keeper, 1 Seeker, 3 Chasers, and 2 Beaters) and the number of goals, which is zero at the beginning of the game. +- It has a method called `setGoal`, and after calling it, the number of goals increases by one. However, this method is private. +- Also, we have another method called `play`. After calling this method, the team will start playing the game, and if the conditions are met, then the `setGoal` method will be called. + +##### Setting Goal Conditions: +When the keeper of the team is successful in saving the goal, at least one beater is successful, and at least two chasers are successful in the match, then the team will score a goal. + +##### Winning Conditions: +When a seeker of a team finds the golden snitch, the team will get 150 scores and will win the match. Otherwise, the team with the most goals will win the match. + +#### Match +After you've created the `Team` class, it's time for the `Match` class. In this class, you will need to create two teams initially. Then, you create a method called `start`. This method will start the game. + +##### Game Starting: +The game consists of 100 rounds. In each round, both teams will play, and after finishing the game, the scores of both teams will be shown, and also the winning team will be shown as the winner. Don't forget that the game can also end in a draw. + +#### MyApp +The final class you need is the `MyApp` class. In this class, you will create a match and start that match in your `main` method. Run the program and enjoy it! diff --git a/Answers/_40230112134/pom.xml b/Answers/_40230112134/pom.xml new file mode 100644 index 0000000..2162428 --- /dev/null +++ b/Answers/_40230112134/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + _40230112134 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/Answers/_40230112134/src/main/java/org/example/Main.java b/Answers/_40230112134/src/main/java/org/example/Main.java new file mode 100644 index 0000000..5d827c2 --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Main.java @@ -0,0 +1,6 @@ +package org.example; + + +public class Main { + +} \ No newline at end of file diff --git a/Answers/_40230112134/src/main/java/org/example/Player.java b/Answers/_40230112134/src/main/java/org/example/Player.java new file mode 100644 index 0000000..4859407 --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Player.java @@ -0,0 +1,107 @@ +package org.example; + +import java.util.Random; + +class Player implements Success +{ + Random MakeRandomNumber = new Random(); + int c = MakeRandomNumber.nextInt(100); + String name; + int number ; + public void setPlayer(String name , int number) + { + this.name = name; + this.number = number; + } + @Override + public int isSuccessful() + { + return 2; + } +} +class Keeper extends Player +{ + public void setKeeper(String name, int number) + { + this.name = name; + this.number = number; + } + @Override + public int isSuccessful() + { + if (c < 70) + { + c = 1; + } + else + { + c = 0; + } + return c; + } +} +class Seeker extends Player +{ + + public void setSeeker(String name, int number) + { + this.name = name; + this.number = number; + } + @Override + public int isSuccessful() + { + if (c < 5) + { + c = 1; + } + else + { + c = 0; + } + return c; + } +} +class Chaser extends Player +{ + public void setChaser(String name, int number) + { + this.name = name; + this.number = number; + } + @Override + public int isSuccessful() + { + if (c < 30) + { + c = 1; + } + else + { + c = 0; + } + return c ; + } +} +class Beater extends Player +{ + public void setBeater(String name, int number) + { + this.name = name; + this.number = number; + } + + @Override + public int isSuccessful() + { + if (c < 40) + { + c = 1; + } + else + { + c = 0; + } + return c; + } +} diff --git a/Answers/_40230112134/src/main/java/org/example/Success.java b/Answers/_40230112134/src/main/java/org/example/Success.java new file mode 100644 index 0000000..cc9c385 --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Success.java @@ -0,0 +1,5 @@ +package org.example; + +public interface Success { + int isSuccessful(); +} From 14863e2e94dc22ce34e5bf71b8349b9ca6d0a7b7 Mon Sep 17 00:00:00 2001 From: "Amir.Homa" Date: Sat, 13 Apr 2024 22:21:29 +0330 Subject: [PATCH 2/3] add Team and Success classes --- .../src/main/java/org/example/Main.java | 6 --- .../src/main/java/org/example/Match.java | 37 +++++++++++++ .../src/main/java/org/example/MyApp.java | 9 ++++ .../src/main/java/org/example/Player.java | 2 +- .../src/main/java/org/example/Team.java | 53 +++++++++++++++++++ 5 files changed, 100 insertions(+), 7 deletions(-) delete mode 100644 Answers/_40230112134/src/main/java/org/example/Main.java create mode 100644 Answers/_40230112134/src/main/java/org/example/Match.java create mode 100644 Answers/_40230112134/src/main/java/org/example/MyApp.java create mode 100644 Answers/_40230112134/src/main/java/org/example/Team.java diff --git a/Answers/_40230112134/src/main/java/org/example/Main.java b/Answers/_40230112134/src/main/java/org/example/Main.java deleted file mode 100644 index 5d827c2..0000000 --- a/Answers/_40230112134/src/main/java/org/example/Main.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.example; - - -public class Main { - -} \ No newline at end of file diff --git a/Answers/_40230112134/src/main/java/org/example/Match.java b/Answers/_40230112134/src/main/java/org/example/Match.java new file mode 100644 index 0000000..d172b0f --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Match.java @@ -0,0 +1,37 @@ +package org.example; + +public class Match extends Team +{ + Team team1 = new Team(); + int ScoreTeam1 = 0; + int ScoreTeam2 = 0; + Team team2 = new Team(); + public void Start() + { + for (int i = 0; i < 100; i++) + { + team1.play(); + team2.play(); + if (team1.seeker.isSuccessful() == 1) + { + ScoreTeam1 += 150; + break; + } + if (team2.seeker.isSuccessful() == 1) + { + ScoreTeam2 += 150; + break; + } + } + for (int i = 0; i < team1.goal; i++) + { + ScoreTeam1 +=10; + } + for (int i = 0; i < team2.goal; i++) + { + ScoreTeam2 +=10; + } + + } + +} diff --git a/Answers/_40230112134/src/main/java/org/example/MyApp.java b/Answers/_40230112134/src/main/java/org/example/MyApp.java new file mode 100644 index 0000000..ff54357 --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/MyApp.java @@ -0,0 +1,9 @@ +package org.example; + +public class MyApp { + public static void Main () + { + Match match = new Match(); + + } +} diff --git a/Answers/_40230112134/src/main/java/org/example/Player.java b/Answers/_40230112134/src/main/java/org/example/Player.java index 4859407..f443e4e 100644 --- a/Answers/_40230112134/src/main/java/org/example/Player.java +++ b/Answers/_40230112134/src/main/java/org/example/Player.java @@ -8,7 +8,7 @@ class Player implements Success int c = MakeRandomNumber.nextInt(100); String name; int number ; - public void setPlayer(String name , int number) + public void setPlayer(String name, int number) { this.name = name; this.number = number; diff --git a/Answers/_40230112134/src/main/java/org/example/Team.java b/Answers/_40230112134/src/main/java/org/example/Team.java new file mode 100644 index 0000000..bee759b --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Team.java @@ -0,0 +1,53 @@ +package org.example; + +public class Team extends Player +{ + Keeper keeper = new Keeper(); + Seeker seeker; + Chaser[] chasers; + Beater[] beaters; + int goal; + + public void setTeam(Keeper keeper, Seeker seeker, Chaser[] chasers, Beater[] beaters) + { + this.keeper = keeper; + this.seeker = seeker; + this.chasers = chasers; + this.beaters = beaters; + this.goal = 0; + } + private void setGoal() + { + goal ++; + } + public void play() + { + int CHCH , BB ; + int K = keeper.isSuccessful(); + int B1 = beaters[0].isSuccessful(); + int B2 = beaters[1].isSuccessful(); + int CH1 = chasers[0].isSuccessful(); + int CH2 = chasers[1].isSuccessful(); + int CH3 = chasers[2].isSuccessful(); + if ((CH1 == 1 && CH2 == 1 && CH3 == 0) || (CH1 == 1 && CH2 == 0 && CH3 == 1) || (CH1 == 0 && CH2 == 1 && CH3 == 1) || (CH1 == 1 && CH2 == 1 && CH3 == 1)) + { + CHCH = 1; + } + else + { + CHCH = 0; + } + if ((B1 == 1 && B2 == 0) || (B1 == 1 && B2 == 1) || (B1 == 0 && B2 == 1)) + { + BB = 1; + } + else + { + BB = 0; + } + if (K ==1 && CHCH == 1 && BB == 1) + { + setGoal(); + } + } +} From aba5b86ce0b4cb0ad1df4552b81190f77a74e3da Mon Sep 17 00:00:00 2001 From: "Amir.Homa" Date: Sun, 14 Apr 2024 14:23:56 +0330 Subject: [PATCH 3/3] add MyApp class --- .../src/main/java/org/example/Match.java | 7 ++- .../src/main/java/org/example/MyApp.java | 29 ++++++++++++- .../src/main/java/org/example/Player.java | 43 +++++++++---------- .../src/main/java/org/example/Success.java | 3 +- .../src/main/java/org/example/Team.java | 24 ++++++----- 5 files changed, 71 insertions(+), 35 deletions(-) diff --git a/Answers/_40230112134/src/main/java/org/example/Match.java b/Answers/_40230112134/src/main/java/org/example/Match.java index d172b0f..ea12406 100644 --- a/Answers/_40230112134/src/main/java/org/example/Match.java +++ b/Answers/_40230112134/src/main/java/org/example/Match.java @@ -6,6 +6,12 @@ public class Match extends Team int ScoreTeam1 = 0; int ScoreTeam2 = 0; Team team2 = new Team(); + + public Match() + { + super(); + } + public void Start() { for (int i = 0; i < 100; i++) @@ -31,7 +37,6 @@ public void Start() { ScoreTeam2 +=10; } - } } diff --git a/Answers/_40230112134/src/main/java/org/example/MyApp.java b/Answers/_40230112134/src/main/java/org/example/MyApp.java index ff54357..3c56afe 100644 --- a/Answers/_40230112134/src/main/java/org/example/MyApp.java +++ b/Answers/_40230112134/src/main/java/org/example/MyApp.java @@ -1,9 +1,36 @@ package org.example; public class MyApp { - public static void Main () + public static void main(String[] args) { Match match = new Match(); + match.Start(); + System.out.println(match.ScoreTeam1); + System.out.println(match.ScoreTeam2); + + if (match.team1.seeker.isSuccessful() == 1) + { + System.out.println("Team1 win"); + } + else if (match.team2.seeker.isSuccessful() == 1) + { + System.out.println("Team2 win"); + } + else + { + if (match.ScoreTeam1 > match.ScoreTeam2) + { + System.out.println("Team1 win"); + } + else if (match.ScoreTeam1 == match.ScoreTeam2) + { + System.out.println("Draw"); + } + else if (match.ScoreTeam1 < match.ScoreTeam2) + { + System.out.println("Team2 win"); + } + } } } diff --git a/Answers/_40230112134/src/main/java/org/example/Player.java b/Answers/_40230112134/src/main/java/org/example/Player.java index f443e4e..8baac45 100644 --- a/Answers/_40230112134/src/main/java/org/example/Player.java +++ b/Answers/_40230112134/src/main/java/org/example/Player.java @@ -2,33 +2,29 @@ import java.util.Random; -class Player implements Success +abstract class Player implements Success { - Random MakeRandomNumber = new Random(); - int c = MakeRandomNumber.nextInt(100); + String name; int number ; - public void setPlayer(String name, int number) + public Player(String name, int number) { this.name = name; this.number = number; } - @Override - public int isSuccessful() - { - return 2; - } } class Keeper extends Player { - public void setKeeper(String name, int number) + + public Keeper(String name, int number) { - this.name = name; - this.number = number; + super(name, number); } @Override public int isSuccessful() { + Random MakeRandomNumber = new Random(); + int c = MakeRandomNumber.nextInt(100); if (c < 70) { c = 1; @@ -43,14 +39,16 @@ public int isSuccessful() class Seeker extends Player { - public void setSeeker(String name, int number) + + public Seeker(String name, int number) { - this.name = name; - this.number = number; + super(name, number); } @Override public int isSuccessful() { + Random MakeRandomNumber = new Random(); + int c = MakeRandomNumber.nextInt(100); if (c < 5) { c = 1; @@ -64,14 +62,15 @@ public int isSuccessful() } class Chaser extends Player { - public void setChaser(String name, int number) + public Chaser(String name, int number) { - this.name = name; - this.number = number; + super(name, number); } @Override public int isSuccessful() { + Random MakeRandomNumber = new Random(); + int c = MakeRandomNumber.nextInt(100); if (c < 30) { c = 1; @@ -85,15 +84,15 @@ public int isSuccessful() } class Beater extends Player { - public void setBeater(String name, int number) + public Beater(String name, int number) { - this.name = name; - this.number = number; + super(name, number); } - @Override public int isSuccessful() { + Random MakeRandomNumber = new Random(); + int c = MakeRandomNumber.nextInt(100); if (c < 40) { c = 1; diff --git a/Answers/_40230112134/src/main/java/org/example/Success.java b/Answers/_40230112134/src/main/java/org/example/Success.java index cc9c385..f56d469 100644 --- a/Answers/_40230112134/src/main/java/org/example/Success.java +++ b/Answers/_40230112134/src/main/java/org/example/Success.java @@ -1,5 +1,6 @@ package org.example; -public interface Success { +public interface Success +{ int isSuccessful(); } diff --git a/Answers/_40230112134/src/main/java/org/example/Team.java b/Answers/_40230112134/src/main/java/org/example/Team.java index bee759b..f2367f1 100644 --- a/Answers/_40230112134/src/main/java/org/example/Team.java +++ b/Answers/_40230112134/src/main/java/org/example/Team.java @@ -1,19 +1,23 @@ package org.example; -public class Team extends Player +public class Team { - Keeper keeper = new Keeper(); + Keeper keeper; Seeker seeker; - Chaser[] chasers; - Beater[] beaters; + Chaser[] chasers = new Chaser[3]; + Beater[] beaters = new Beater[2]; int goal; - public void setTeam(Keeper keeper, Seeker seeker, Chaser[] chasers, Beater[] beaters) + public Team() { - this.keeper = keeper; - this.seeker = seeker; - this.chasers = chasers; - this.beaters = beaters; + super(); + this.keeper = new Keeper("hosein" , 6); + this.seeker = new Seeker("hasan",5); + this.chasers[0] = new Chaser("amir",3); + this.chasers[1] = new Chaser("harry",10); + this.chasers[2] = new Chaser("tom",2); + this.beaters[0] = new Beater("ALI",1); + this.beaters[1] = new Beater("AmirAli",15); this.goal = 0; } private void setGoal() @@ -45,7 +49,7 @@ public void play() { BB = 0; } - if (K ==1 && CHCH == 1 && BB == 1) + if (K == 1 && CHCH == 1 && BB == 1) { setGoal(); }