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/Match.java b/Answers/_40230112134/src/main/java/org/example/Match.java new file mode 100644 index 0000000..ea12406 --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Match.java @@ -0,0 +1,42 @@ +package org.example; + +public class Match extends Team +{ + Team team1 = new Team(); + int ScoreTeam1 = 0; + int ScoreTeam2 = 0; + Team team2 = new Team(); + + public Match() + { + super(); + } + + 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..3c56afe --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/MyApp.java @@ -0,0 +1,36 @@ +package org.example; + +public class MyApp { + 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 new file mode 100644 index 0000000..8baac45 --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Player.java @@ -0,0 +1,106 @@ +package org.example; + +import java.util.Random; + +abstract class Player implements Success +{ + + String name; + int number ; + public Player(String name, int number) + { + this.name = name; + this.number = number; + } +} +class Keeper extends Player +{ + + public Keeper(String name, int number) + { + super(name, number); + } + @Override + public int isSuccessful() + { + Random MakeRandomNumber = new Random(); + int c = MakeRandomNumber.nextInt(100); + if (c < 70) + { + c = 1; + } + else + { + c = 0; + } + return c; + } +} +class Seeker extends Player +{ + + + public Seeker(String name, int number) + { + super(name, number); + } + @Override + public int isSuccessful() + { + Random MakeRandomNumber = new Random(); + int c = MakeRandomNumber.nextInt(100); + if (c < 5) + { + c = 1; + } + else + { + c = 0; + } + return c; + } +} +class Chaser extends Player +{ + public Chaser(String name, int number) + { + super(name, number); + } + @Override + public int isSuccessful() + { + Random MakeRandomNumber = new Random(); + int c = MakeRandomNumber.nextInt(100); + if (c < 30) + { + c = 1; + } + else + { + c = 0; + } + return c ; + } +} +class Beater extends Player +{ + public Beater(String name, int number) + { + super(name, number); + } + @Override + public int isSuccessful() + { + Random MakeRandomNumber = new Random(); + int c = MakeRandomNumber.nextInt(100); + 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..f56d469 --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Success.java @@ -0,0 +1,6 @@ +package org.example; + +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 new file mode 100644 index 0000000..f2367f1 --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Team.java @@ -0,0 +1,57 @@ +package org.example; + +public class Team +{ + Keeper keeper; + Seeker seeker; + Chaser[] chasers = new Chaser[3]; + Beater[] beaters = new Beater[2]; + int goal; + + public Team() + { + 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() + { + 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(); + } + } +}