Skip to content

All Done . . . #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.example;

public class Beater extends Player{

public Beater(String name , int number , int chance){
super(name,number,chance);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.example;

public class Chaser extends Player{

public Chaser(String name , int number , int chance){
super(name,number,chance);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.example;

public class Keeper extends Player{

public Keeper(String name , int number , int chance){
super(name,number,chance);
}
}
44 changes: 44 additions & 0 deletions Answers/Quidditch_40230112063/src/main/java/org/example/Match.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.example;

public class Match {

Team team1 = new Team();
Team team2 = new Team();

public void winner(String winner_team_name, Team team1, Team team2 ) {
System.out.println("Number of goals , team1 = " + team1.getGoal());
System.out.println("Number of goals , team2 = " + team2.getGoal());
System.out.println("Winner : " + winner_team_name);

}


public void start() {
for (int i = 0; i < 100; i++) {
if (team1.goldenSnitch()) {
System.out.println("Golden Snitch");
winner("team1", team1, team2);
return;
} else if (team2.goldenSnitch()) {
System.out.println("Golden Snitch");
winner("team2", team1, team2);
return;
} else {
team1.play();
team2.play();
}
}

if (team1.getGoal() > team2.getGoal()) {
winner("team1", team1, team2);
} else if (team2.getGoal() > team1.getGoal()) {
winner("team2", team1, team2);

} else {
System.out.println("Number of goals , team1 = " + team1.getGoal());
System.out.println("Number of goals , team2 = " + team2.getGoal());
System.out.println(" Draw ");
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.example;

public class MyApp {
public static void main(String[] args){
Match math = new Match();

math.start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.example;
import java.util.Random;

public class Player implements Success {

private int chance , number;
private String name ;

Random random = new Random();

@Override
public boolean isSuccessful() {
random.setSeed(System.currentTimeMillis());
int random_number = (random.nextInt(100))+1; // generates a number between 1 and 100
return (random_number<=chance);
}

public Player(String name , int number , int chance){
this.chance = chance;
this.name = name;
this.number = number;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.example;

public class Seeker extends Player{

public Seeker(String name , int number , int chance){
super(name,number,chance);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.example;

public interface Success {

boolean isSuccessful();
}
52 changes: 52 additions & 0 deletions Answers/Quidditch_40230112063/src/main/java/org/example/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.example;

public class Team {

private Keeper keeper;
private Seeker seeker;
private Chaser chaser1;
private Chaser chaser2;
private Chaser chaser3;
private Beater beater1;
private Beater beater2;
private int number_of_goals;

public Team() {
this.keeper = new Keeper("keeper", 1, 70);
this.seeker = new Seeker("seeker", 1, 5);
this.chaser1 = new Chaser("chaser", 1, 30);
this.chaser2 = new Chaser("chaser", 2, 30);
this.chaser3 = new Chaser("chaser", 3, 30);
this.beater1 = new Beater("beater", 1, 40);
this.beater2 = new Beater("beater", 2, 40);
this.number_of_goals = 0;
}

private void setGoal() {
number_of_goals++;
}

public int getGoal() {
return number_of_goals;
}


public boolean goldenSnitch() {
if (seeker.isSuccessful()) {
number_of_goals += 150;
return true;
}
return false;
}


public void play() {

if (keeper.isSuccessful() &&
(beater1.isSuccessful() || beater2.isSuccessful()) &&
((chaser1.isSuccessful() && chaser2.isSuccessful()) || (chaser1.isSuccessful() && chaser3.isSuccessful())
|| (chaser2.isSuccessful() && chaser3.isSuccessful()))) {
setGoal();
}
}
}