Skip to content
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

Done #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Done #26

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
3 changes: 3 additions & 0 deletions Answers/40230212039/project3/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Answers/40230212039/project3/.idea/description.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Answers/40230212039/project3/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Answers/40230212039/project3/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Answers/40230212039/project3/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Answers/40230212039/project3/.idea/project-template.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions Answers/40230212039/project3/project3.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
16 changes: 16 additions & 0 deletions Answers/40230212039/project3/src/Beater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.Random;

public class Beater extends Player implements Success{

Beater(String name , int number){
super(name , number);
}

public boolean isSuccessful(){
Random randomNum = new Random();
int random = randomNum.nextInt(100) +1;
if (random <= 40){
return true;
} else {return false;}
}
}
17 changes: 17 additions & 0 deletions Answers/40230212039/project3/src/Chaser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.Random;

public class Chaser extends Player implements Success{

Chaser(String name , int number){
super(name , number);
}

public boolean isSuccessful(){

Random randomNum = new Random();
int random = randomNum.nextInt(100) +1;
if (random <=30){
return true;
} else {return false;}
}
}
17 changes: 17 additions & 0 deletions Answers/40230212039/project3/src/Keeper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.Random;

public class Keeper extends Player implements Success {

Keeper (String name , int number){
super( name , number);
}

public boolean isSuccessful(){

Random randomNum = new Random();
int random = randomNum.nextInt(100) +1;
if (random <=70){
return true;
} else {return false;}
}
}
6 changes: 6 additions & 0 deletions Answers/40230212039/project3/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Main {
public static void main(String[] args){


}
}
41 changes: 41 additions & 0 deletions Answers/40230212039/project3/src/Match.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
public class Match {

public void start () {

Team teamNo1 = new Team();
Team teamNo2 = new Team();

for (int i = 0; i < 100; i++) {
teamNo1.play();
if (teamNo1.snitch) {
break;
}
teamNo2.play();
if (teamNo2.snitch) {
break;
}
}

if (teamNo1.snitch) {
System.out.println("Team 1 got the golden snitch.");
System.out.println("Team 1 : " + (teamNo1.goals + 150));
System.out.println("Team 2 : " + teamNo2.goals);
System.out.println("Team 1 WINS!!");
} else if (teamNo2.snitch) {
System.out.println("Team 2 got the golden snitch.");
System.out.println("Team 2 : " + (teamNo2.goals + 150));
System.out.println("Team 1 : " + teamNo1.goals);
System.out.println("Team 2 WINS!!");
} else if (teamNo1.goals > teamNo2.goals) {
System.out.println("Team 1 got " + teamNo1.goals + " scores and team 2 got " + teamNo2.goals + " scores.");
System.out.println("Team 1 WINS!!");
} else if (teamNo2.goals > teamNo1.goals) {
System.out.println("Team 2 got " + teamNo2.goals + " scores and team 1 got " + teamNo1.goals + " scores.");
System.out.println("Team 2 WINS!!");
} else if (teamNo2.goals == teamNo1.goals) {
System.out.println("The final score for team 1 is " + teamNo1.goals + " and for team 2 is " + teamNo2.goals);
System.out.println("So the game ends in a draw!");
}
}
}

7 changes: 7 additions & 0 deletions Answers/40230212039/project3/src/Myapp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class Myapp {
public static void main(String[] args) {
Match match = new Match();
match.start();

}
}
14 changes: 14 additions & 0 deletions Answers/40230212039/project3/src/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Player implements Success{

public String name;
public int number;

Player (String name , int number){
this.name = name;
this.number = number;
}

public boolean isSuccessful(){
return false;
}
}
17 changes: 17 additions & 0 deletions Answers/40230212039/project3/src/Seeker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.Random;

public class Seeker extends Player implements Success{

Seeker(String name , int number){
super(name , number);
}

public boolean isSuccessful(){

Random randomNum = new Random();
int random = randomNum.nextInt(100) +1;
if (random <=5){
return true;
} else {return false;}
}
}
3 changes: 3 additions & 0 deletions Answers/40230212039/project3/src/Success.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface Success {
public boolean isSuccessful();
}
32 changes: 32 additions & 0 deletions Answers/40230212039/project3/src/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Team {

Keeper keeper1= new Keeper("keeper" , 1);
Beater beater1 = new Beater("beater" , 2);
Beater beater2 = new Beater("beater" , 3);
Chaser chaser1 = new Chaser("chaser" , 4);
Chaser chaser2 = new Chaser("chaser" , 5);
Chaser chaser3 = new Chaser("chaser" , 6);
Seeker seeker1 = new Seeker("seeker" , 7);

int goals = 0;
private void setGoal(){
goals++;
}

boolean snitch = false;
public void play() {
if (seeker1.isSuccessful()) {
snitch = true;
}

if (keeper1.isSuccessful()) {
if (beater1.isSuccessful() || beater2.isSuccessful()) {
if ((chaser1.isSuccessful() && chaser2.isSuccessful()) ||
(chaser2.isSuccessful() && chaser3.isSuccessful()) ||
(chaser1.isSuccessful() && chaser3.isSuccessful())) {
setGoal();
}
}
}
}
}
1 change: 1 addition & 0 deletions Answers/40230212039/project3/src/com/company/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@