Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Answers/40230112050/Beater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.Random;

public class Beater extends Player implements Success {
@Override
public boolean isSuccessful() {

boolean status =false ;

int randnumber ;

Random rand = new Random();
randnumber = rand.nextInt(100)+1;

if (randnumber<=30)
status = true ;


return status;


}
}
21 changes: 21 additions & 0 deletions Answers/40230112050/Chaser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Random;

public class Chaser extends Player implements Success{
@Override
public boolean isSuccessful() {

boolean status =false ;

int randnumber ;

Random rand = new Random();
randnumber = rand.nextInt(100)+1;

if (randnumber<=40)
status = true ;


return status;

}
}
20 changes: 20 additions & 0 deletions Answers/40230112050/Keeper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.Random;

public class Keeper extends Player implements Success{
@Override
public boolean isSuccessful() {

boolean status =false ;

int randnumber ;

Random rand = new Random();
randnumber = rand.nextInt(100)+1;

if (randnumber<=70)
status = true ;


return status;
}
}
8 changes: 8 additions & 0 deletions Answers/40230112050/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutte
public class Main {
public static void main(String[] args) {
MyApp myapp = new MyApp();
myapp.str();
}
}
14 changes: 14 additions & 0 deletions Answers/40230112050/Match.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.util.Objects;

public class Match {

public void start(String n) {
if(Objects.equals(n, "start")){
Team team = new Team();
team.Play();
}



}
}
12 changes: 12 additions & 0 deletions Answers/40230112050/MyApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import java.util.Scanner;

public class MyApp {
public void str() {
System.out.println("please type start:");
Scanner input = new Scanner(System.in);
String n = input.nextLine();
Match match = new Match();
match.start(n);

}
}
2 changes: 2 additions & 0 deletions Answers/40230112050/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class Player {
}
21 changes: 21 additions & 0 deletions Answers/40230112050/Seeker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Random;

public class Seeker extends Player implements Success{
@Override
public boolean isSuccessful() {

boolean status =false ;

int randnumber ;

Random rand = new Random();
randnumber = rand.nextInt(100)+1;

if (randnumber<=5)
status = true ;


return status;

}
}
3 changes: 3 additions & 0 deletions Answers/40230112050/Success.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface Success {
boolean isSuccessful();
}
102 changes: 102 additions & 0 deletions Answers/40230112050/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import com.sun.security.jgss.GSSUtil;

public class Team {
int s = 0 ;

Chaser chaser11 = new Chaser();
Chaser chaser12 = new Chaser();
Chaser chaser13 = new Chaser();
Chaser chaser21 = new Chaser();
Chaser chaser22 = new Chaser();
Chaser chaser23 = new Chaser();
Beater beater11 = new Beater();
Beater beater12 = new Beater();
Beater beater21 = new Beater();
Beater beater22 = new Beater();
Seeker seeker1 = new Seeker();
Seeker seeker2 = new Seeker();
Keeper keeper1 = new Keeper();
Keeper keeper2 = new Keeper();

int goal1 = 0;
int goal2 = 0;

public void Play() {
for(int i = 0 ; i < 100 ; i++) {
Team1();
Team2();
if (seeker1.isSuccessful()){
System.out.println("team1 found gold snitch!!!!!");
System.out.println("team1 won");
s = 1;
break;
}
if (seeker2.isSuccessful()){
System.out.println("team2 found gold snitch!!!!!");
System.out.println("team2 won");
s = 1;
break;
}
}
if(s != 1) {
System.out.format("team1 score:%d \nteam2 score:%d\n", getGoal1(goal1), getGoal2(goal2));
if (getGoal1(goal1) > getGoal2(goal2)) {
System.out.println("\nTeam1 won!!");

} else if (getGoal1(goal1) < getGoal2(goal2)) {
System.out.println("\nTeam2 won!!");

} else {
System.out.println("\nDraw");
}
}


}



public void Team1 () {
if (keeper1.isSuccessful()) {
if (beater11.isSuccessful() || beater12.isSuccessful()) {
if ((chaser11.isSuccessful() && chaser12.isSuccessful()) || (chaser11.isSuccessful() && chaser13.isSuccessful()) || (chaser12.isSuccessful() && chaser13.isSuccessful())) {
setgoal1();
}
}
}



}

private void setgoal1 () {
goal1++;

}
public int getGoal1(int goal1){
return goal1;
}

public void Team2 (){
if (keeper2.isSuccessful()) {
if (beater21.isSuccessful() || beater22.isSuccessful()) {
if ((chaser21.isSuccessful() && chaser22.isSuccessful()) || (chaser21.isSuccessful() && chaser23.isSuccessful()) || (chaser22.isSuccessful() && chaser23.isSuccessful())) {
setgoal2();
}
}
}


}
private void setgoal2 () {
goal2++;

}
public int getGoal2(int goal2){
return goal2;
}




}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 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.
In this assignment, w[README.md](README.md)e 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!
Expand All @@ -26,7 +26,7 @@ The beater has a 40% chance to stop chasers.
- 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.
- Create a class for `Team`. This class contains players of your team (1 Keeper, 1 Seeker, 3 Chasers, and 2 Beater) 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.

Expand Down