From 37655fb2653a7eb92229bf13baae85b4cb3aeb16 Mon Sep 17 00:00:00 2001 From: touka6 Date: Sun, 14 Apr 2024 21:21:21 +0330 Subject: [PATCH 1/2] there are still some problems to be solved --- Answers/40230112113/Beater.java | 20 +++++++++++++++ Answers/40230112113/Chaser.java | 21 ++++++++++++++++ Answers/40230112113/Keeper.java | 13 ++++++++++ Answers/40230112113/Match.java | 18 ++++++++++++++ Answers/40230112113/MyApp.java | 42 ++++++++++++++++++++++++++++++++ Answers/40230112113/Player.java | 10 ++++++++ Answers/40230112113/Seeker.java | 13 ++++++++++ Answers/40230112113/Success.java | 4 +++ Answers/40230112113/Team.java | 30 +++++++++++++++++++++++ 9 files changed, 171 insertions(+) create mode 100644 Answers/40230112113/Beater.java create mode 100644 Answers/40230112113/Chaser.java create mode 100644 Answers/40230112113/Keeper.java create mode 100644 Answers/40230112113/Match.java create mode 100644 Answers/40230112113/MyApp.java create mode 100644 Answers/40230112113/Player.java create mode 100644 Answers/40230112113/Seeker.java create mode 100644 Answers/40230112113/Success.java create mode 100644 Answers/40230112113/Team.java diff --git a/Answers/40230112113/Beater.java b/Answers/40230112113/Beater.java new file mode 100644 index 0000000..10c3f6c --- /dev/null +++ b/Answers/40230112113/Beater.java @@ -0,0 +1,20 @@ +public class Beater extends Player +{ + public Boolean isSuccessful() + { + int count = 0; + int random=(int)(Math.random()*100); + Boolean check; + + for (int i=1;i<=2;i++) + { + if (random<=40) + count++; + } + if (count>=1) + check=true; + else + check=false; + return check; + } +} diff --git a/Answers/40230112113/Chaser.java b/Answers/40230112113/Chaser.java new file mode 100644 index 0000000..ccec407 --- /dev/null +++ b/Answers/40230112113/Chaser.java @@ -0,0 +1,21 @@ +public class Chaser extends Player +{ + public Boolean isSuccessful() + { + int count=0; + int random=(int)(Math.random()*100); + Boolean check; + + for(int i=1;i<=3;i++) + { + if (random<=30) + count++; + } + if (count>=2) + check=true; + else + check=false; + return check; + + } +} diff --git a/Answers/40230112113/Keeper.java b/Answers/40230112113/Keeper.java new file mode 100644 index 0000000..f607148 --- /dev/null +++ b/Answers/40230112113/Keeper.java @@ -0,0 +1,13 @@ +public class Keeper extends Player +{ + public Boolean isSuccessful() + { + int random=(int)(Math.random()*100); + Boolean check; + if (random<=70) + check=true; + else + check=false; + return check; + } +} diff --git a/Answers/40230112113/Match.java b/Answers/40230112113/Match.java new file mode 100644 index 0000000..e368e90 --- /dev/null +++ b/Answers/40230112113/Match.java @@ -0,0 +1,18 @@ +public class Match +{ + Team team1 = new Team(); + Team team2 = new Team(); + + public void start() + { + for(int i=1;i<=100;i++) + { + team1.play(); + team1.goals=team1.goals; + team2.play(); + team2.goals=team2.goals; + if((team1.caught==true)||(team2.caught==true)) + break; + } + } +} diff --git a/Answers/40230112113/MyApp.java b/Answers/40230112113/MyApp.java new file mode 100644 index 0000000..7e2ce45 --- /dev/null +++ b/Answers/40230112113/MyApp.java @@ -0,0 +1,42 @@ +public class MyApp +{ + public static void main(String[] args) + { + Match match = new Match(); + Team team1 = new Team(); + Team team2 = new Team(); + + match.start(); + + if (team1.caught==true) + { + System.out.println("Team 1 scores: "+team1.goals); + System.out.println("Team 2 scored: "+team2.goals); + System.out.println("TEAM 1 WINS!"); + } + else if(team2.caught==true) + { + System.out.println("Team 1 scored: "+team1.goals); + System.out.println("Team 2 scored: "+team2.goals); + System.out.println("TEAM 2 WINS!"); + } + 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 Date: Sun, 14 Apr 2024 23:51:09 +0330 Subject: [PATCH 2/2] new files uploaded --- Answers/40230112113/Beater.java | 24 ++++++++------------ Answers/40230112113/Chaser.java | 25 ++++++++------------- Answers/40230112113/Keeper.java | 17 +++++++------- Answers/40230112113/Match.java | 12 ++++++---- Answers/40230112113/MyApp.java | 39 +++++++++++++++++++-------------- Answers/40230112113/Player.java | 6 ++++- Answers/40230112113/Seeker.java | 17 +++++++------- Answers/40230112113/Team.java | 38 +++++++++++++++++++++++--------- 8 files changed, 99 insertions(+), 79 deletions(-) diff --git a/Answers/40230112113/Beater.java b/Answers/40230112113/Beater.java index 10c3f6c..a3e0600 100644 --- a/Answers/40230112113/Beater.java +++ b/Answers/40230112113/Beater.java @@ -1,20 +1,14 @@ +import java.util.Random; + public class Beater extends Player { - public Boolean isSuccessful() + public Beater (String name, int number) { - int count = 0; - int random=(int)(Math.random()*100); - Boolean check; - - for (int i=1;i<=2;i++) - { - if (random<=40) - count++; - } - if (count>=1) - check=true; - else - check=false; - return check; + super(name, number); + } + public Boolean isSuccessful() { + Random random = new Random(); + int chance = random.nextInt(100); + return chance <= 40; } } diff --git a/Answers/40230112113/Chaser.java b/Answers/40230112113/Chaser.java index ccec407..1d9b580 100644 --- a/Answers/40230112113/Chaser.java +++ b/Answers/40230112113/Chaser.java @@ -1,21 +1,14 @@ +import java.util.Random; + public class Chaser extends Player { - public Boolean isSuccessful() + public Chaser(String name, int number) { - int count=0; - int random=(int)(Math.random()*100); - Boolean check; - - for(int i=1;i<=3;i++) - { - if (random<=30) - count++; - } - if (count>=2) - check=true; - else - check=false; - return check; - + super(name, number); + } + public Boolean isSuccessful() { + Random random = new Random(); + int chance = random.nextInt(100); + return chance <= 30; } } diff --git a/Answers/40230112113/Keeper.java b/Answers/40230112113/Keeper.java index f607148..8cf023a 100644 --- a/Answers/40230112113/Keeper.java +++ b/Answers/40230112113/Keeper.java @@ -1,13 +1,14 @@ +import java.util.Random; + public class Keeper extends Player { - public Boolean isSuccessful() + public Keeper(String name, int number) { - int random=(int)(Math.random()*100); - Boolean check; - if (random<=70) - check=true; - else - check=false; - return check; + super(name, number); + } + public Boolean isSuccessful() { + Random random = new Random(); + int chance = random.nextInt(100); + return chance <= 70; } } diff --git a/Answers/40230112113/Match.java b/Answers/40230112113/Match.java index e368e90..eb02090 100644 --- a/Answers/40230112113/Match.java +++ b/Answers/40230112113/Match.java @@ -1,16 +1,20 @@ public class Match { - Team team1 = new Team(); - Team team2 = new Team(); + 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(); - team1.goals=team1.goals; team2.play(); - team2.goals=team2.goals; if((team1.caught==true)||(team2.caught==true)) break; } diff --git a/Answers/40230112113/MyApp.java b/Answers/40230112113/MyApp.java index 7e2ce45..f70ab7e 100644 --- a/Answers/40230112113/MyApp.java +++ b/Answers/40230112113/MyApp.java @@ -2,35 +2,40 @@ public class MyApp { public static void main(String[] args) { - Match match = new Match(); - Team team1 = new Team(); - Team team2 = new Team(); + 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.caught==true) - { - System.out.println("Team 1 scores: "+team1.goals); - System.out.println("Team 2 scored: "+team2.goals); - System.out.println("TEAM 1 WINS!"); - } - else if(team2.caught==true) - { - System.out.println("Team 1 scored: "+team1.goals); - System.out.println("Team 2 scored: "+team2.goals); - System.out.println("TEAM 2 WINS!"); - } 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!"); + System.out.println("TEAM 1 WINS!"); } else if (team1.goals