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
14 changes: 14 additions & 0 deletions Answers/40230112113/Beater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.util.Random;

public class Beater extends Player
{
public Beater (String name, int number)
{
super(name, number);
}
public Boolean isSuccessful() {
Random random = new Random();
int chance = random.nextInt(100);
return chance <= 40;
}
}
14 changes: 14 additions & 0 deletions Answers/40230112113/Chaser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.util.Random;

public class Chaser extends Player
{
public Chaser(String name, int number)
{
super(name, number);
}
public Boolean isSuccessful() {
Random random = new Random();
int chance = random.nextInt(100);
return chance <= 30;
}
}
14 changes: 14 additions & 0 deletions Answers/40230112113/Keeper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.util.Random;

public class Keeper extends Player
{
public Keeper(String name, int number)
{
super(name, number);
}
public Boolean isSuccessful() {
Random random = new Random();
int chance = random.nextInt(100);
return chance <= 70;
}
}
22 changes: 22 additions & 0 deletions Answers/40230112113/Match.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Match
{
Team team1;
Team team2;

public Match(Team team1,Team team2)
{
this.team1=team1;
this.team2=team2;
}

public void start()
{
for(int i=1;i<=100;i++)
{
team1.play();
team2.play();
if((team1.caught==true)||(team2.caught==true))
break;
}
}
}
47 changes: 47 additions & 0 deletions Answers/40230112113/MyApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
public class MyApp
{
public static void main(String[] args)
{
Keeper k1=new Keeper("asghar", 1);
Seeker s1=new Seeker("huh", 2);
Chaser c1_1=new Chaser("haha", 3);
Chaser c2_1=new Chaser("hoho", 4);
Chaser c3_1=new Chaser("hehe", 5);
Beater B1_1=new Beater("hehe", 6);
Beater B2_1=new Beater("hehe", 7);

Keeper k2=new Keeper("asghar", 1);
Seeker s2=new Seeker("huh", 2);
Chaser c1_2=new Chaser("haha", 3);
Chaser c2_2=new Chaser("hoho", 4);
Chaser c3_2=new Chaser("hehe", 5);
Beater B1_2=new Beater("hehe", 6);
Beater B2_2=new Beater("hehe", 7);

Team team2=new Team(B1_2, B2_2, s2, k2, c1_2, c2_2, c3_2);
Team team1=new Team(B1_1, B2_1, s1, k1, c1_1, c2_1, c3_1);

Match match = new Match(team1, team2);

match.start();

if(team1.goals>team2.goals)
{
System.out.println("Team 1 scored: "+team1.goals);
System.out.println("Team 2 scored: "+team2.goals);
System.out.println("TEAM 1 WINS!");
}
else if (team1.goals<team2.goals)
{
System.out.println("Team 1 scored: "+team1.goals);
System.out.println("Team 2 scored: "+team2.goals);
System.out.println("TEAM 2 WINS!");
}
else if (team1.goals==team2.goals)
{
System.out.println("Team 1 scored: "+team1.goals);
System.out.println("Team 2 scored: "+team2.goals);
System.out.println("THE GAME ENDS IN A DRAW!!");
}
}
}
14 changes: 14 additions & 0 deletions Answers/40230112113/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Player implements Success
{
String name;
int number;
public Player (String name , int number)
{
this.name=name;
this.number=number;
}
public Boolean isSuccessful()
{
return null;
}
}
14 changes: 14 additions & 0 deletions Answers/40230112113/Seeker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.util.Random;

public class Seeker extends Player
{
public Seeker(String name, int number)
{
super(name, number);
}
public Boolean isSuccessful() {
Random random = new Random();
int chance = random.nextInt(100);
return chance <= 5;
}
}
4 changes: 4 additions & 0 deletions Answers/40230112113/Success.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public interface Success
{
public Boolean isSuccessful();
}
48 changes: 48 additions & 0 deletions Answers/40230112113/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
public class Team
{
Beater B1;
Beater B2;
Seeker S ;
Keeper K ;
Chaser C1;
Chaser C2;
Chaser C3;

int goals;

public Team(Beater B1,Beater B2,Seeker S,Keeper K,Chaser C1,Chaser C2,Chaser C3)
{
this.B1=B1;
this.B2=B2;
this.S=S;
this.K=K;
this.C1=C1;
this.C2=C2;
this.C3=C3;
this.goals=0;
}

public void play()
{
if (K.isSuccessful())
if((B1.isSuccessful())||(B2.isSuccessful()))
if((C1.isSuccessful()&&C2.isSuccessful())||(C1.isSuccessful()&&C3.isSuccessful())||(C2.isSuccessful()&&C3.isSuccessful()))
setGoal();
if(S.isSuccessful())
SeekerScores();

}

public void setGoal()
{
this.goals++;
}

Boolean caught=false;

public void SeekerScores()
{
this.goals+=150;
caught=true;
}
}