Skip to content

Project done #38

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 5 commits into
base: main
Choose a base branch
from
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/Third_Project/.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/Third_Project/.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/Third_Project/.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/Third_Project/.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/Third_Project/.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/Third_Project/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>Third_Project</artifactId>
<version>1.0-SNAPSHOT</version>

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

</project>
28 changes: 28 additions & 0 deletions Answers/Third_Project/src/main/java/Match.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Match {
Team blue = new Team();
Team red = new Team();
public void start(){
for (int i=0; i<100; i++) {
if (blue.getgoal() > 100)
break;
if (red.getgoal() > 100)
break;
blue.play();
red.play();
}
int blue_point = blue.getgoal();
int red_point = red.getgoal();
String result = " ";
if (blue_point > red_point)
result = "The winner is : Blue Team";
else if (red_point > blue_point) {
result = "The winner is : Red Team";
}else {
result = "No Winner Draw !";
}

System.out.println(result);
System.out.println("Blue team : " + blue_point);
System.out.println("Red team : " + red_point);
}
}
6 changes: 6 additions & 0 deletions Answers/Third_Project/src/main/java/MyApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class MyApp {
public static void main(String[] args) {
Match match = new Match();
match.start();
}
}
96 changes: 96 additions & 0 deletions Answers/Third_Project/src/main/java/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import java.util.Random;

public class Player {
private String name;
private int number;
protected Random random;

public Player(String name, int number) {
this.name = name;
this.number = number;
this.random = new Random();
}
protected int getRandomNumber(){
return random.nextInt(101);
}
}

//---------------------------------------------------------------------

class Keeper extends Player implements Success {
private boolean Saved;

public Keeper(String name, int number) {
super(name, number);
this.Saved = false;
}
public void attemptToSaveGoal() {
if (getRandomNumber() <= 70 ) {
Saved = true;
}
}
@Override
public boolean isSuccessful() {
return Saved;
}
}

//---------------------------------------------------------------------

class Seeker extends Player implements Success {
private boolean foundSnitch;

public Seeker(String name, int number) {
super(name, number);
this.foundSnitch = false;
}
public void attemptToFindSnitch() {
if (getRandomNumber() <= 5 ) {
foundSnitch = true;
}
}
@Override
public boolean isSuccessful() {
return foundSnitch;
}
}

//---------------------------------------------------------------------

class Chaser extends Player implements Success {
private boolean Scored;

public Chaser(String name, int number) {
super(name, number);
this.Scored = false;
}
public void attemptToScoreGoal() {
if (getRandomNumber() <= 30 ) {
Scored = true;
}
}
@Override
public boolean isSuccessful() {
return Scored;
}
}

//---------------------------------------------------------------------

class Beater extends Player implements Success {
private boolean Stopped;

public Beater(String name, int number) {
super(name, number);
this.Stopped = false;
}
public void attemptToStopChaser() {
if (getRandomNumber() <= 40 ) {
Stopped = true;
}
}
@Override
public boolean isSuccessful() {
return Stopped;
}
}
3 changes: 3 additions & 0 deletions Answers/Third_Project/src/main/java/Success.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface Success {
public boolean isSuccessful();
}
41 changes: 41 additions & 0 deletions Answers/Third_Project/src/main/java/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
public class Team {
Keeper keeper = new Keeper("keeper",1);
Seeker seeker = new Seeker("seeker",2);
Chaser chaser1 = new Chaser("chaser1",3);
Chaser chaser2 = new Chaser("chaser2",4);
Chaser chaser3 = new Chaser("chaser3",5);
Beater beater1 = new Beater("beater1",6);
Beater beater2 = new Beater("beater2",7);

private int goal = 0;
private void setgoal(){
goal ++;
}
public int getgoal(){
return goal;
}

public void play(){
//game plays
keeper.attemptToSaveGoal();
chaser1.attemptToScoreGoal();
chaser2.attemptToScoreGoal();
chaser3.attemptToScoreGoal();
beater1.attemptToStopChaser();
beater2.attemptToStopChaser();
seeker.attemptToFindSnitch();
//result
boolean SnitchCatched = seeker.isSuccessful();
boolean condition = false;
boolean chasing = (chaser1.isSuccessful() && chaser2.isSuccessful()) || (chaser1.isSuccessful() && chaser3.isSuccessful()) || (chaser2.isSuccessful() && chaser3.isSuccessful());
boolean beating = (beater1.isSuccessful() || beater2.isSuccessful());
boolean keeping = keeper.isSuccessful();
condition = chasing && beating && keeping;

if (SnitchCatched){
goal += 150;
}
if (condition )
setgoal();
}
}