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
38 changes: 38 additions & 0 deletions Answers/Yas_Hassanpour_40231712003/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
3 changes: 3 additions & 0 deletions Answers/Yas_Hassanpour_40231712003/.idea/.gitignore

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

7 changes: 7 additions & 0 deletions Answers/Yas_Hassanpour_40231712003/.idea/encodings.xml

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

14 changes: 14 additions & 0 deletions Answers/Yas_Hassanpour_40231712003/.idea/misc.xml

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

6 changes: 6 additions & 0 deletions Answers/Yas_Hassanpour_40231712003/.idea/vcs.xml

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

17 changes: 17 additions & 0 deletions Answers/Yas_Hassanpour_40231712003/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>Yas_Hassanpour_40231712003</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example;
import java.util.Random;

public class Beater extends Player implements Player.Success {
@Override
public boolean isSuccessful() {
Random randNum = new Random();
if(randNum.nextInt(100)+1<=40)
return true;
else return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.example;

import java.util.Random;

public class Chaser extends Player implements Player.Success{
@Override
public boolean isSuccessful() {
Random randNum = new Random();
if(randNum.nextInt(100)+1<=30)
return true;
else
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.example;

import java.util.Random;

public class Keeper extends Player implements Player.Success{
@Override
public boolean isSuccessful() {
Random randNum= new Random();
if(randNum.nextInt(100)+1<=70)
return true;
else
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.example;

public class Match {
Team team1;
Team team2;
public Match(){
team1= new Team();
team2= new Team();
}
public void start()
{
for (int i=0; i<100; i++) {
team1.play();
team2.play();
}
System.out.println("Team 1: "+ team1.goals);
System.out.println("Team 2: "+team2.goals);

if(team1.goals== team2.goals)
{
System.out.println("It's a draw!");
}
if(team1.goals> team2.goals)
{
System.out.println("Team 1 is the winner!");
}
if(team1.goals< team2.goals)
{
System.out.println("Team 2 is the winner!");
}
}

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


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

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

import java.util.Random;

public class Player {
String name;
int number;
interface Success {
public boolean isSuccessful ();

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

import java.util.Random;

public class Seeker extends Player implements Player.Success{
@Override
public boolean isSuccessful() {
Random randNum = new Random();
if (randNum.nextInt(100)+1<=5)
return true;
else
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.example;

public class Team {
Keeper keeper= new Keeper();
Seeker seeker = new Seeker();
Beater[] beaters = new Beater[2];
Chaser[] chasers = new Chaser[3];
int goals;
public Team() {
for (int i = 0; i < chasers.length; i++) {
chasers[i] = new Chaser();
}
}
private void setGoals()
{
goals++;
}
private boolean
beaterIsSuccessful() {
for (Beater beater : beaters) {
if (beater.isSuccessful()) {
return true;
}
}
return false;
}

private int successfulChasersNum() {
int successfulChasers = 0;
for (Chaser chaser : chasers) {
if (chaser.isSuccessful()) {
successfulChasers++;
}
}
return successfulChasers;
}
public void play()
{
if(keeper.isSuccessful() && successfulChasersNum()>=2)
setGoals();
if(seeker.isSuccessful())
goals=+150;
}
}