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/40230112119/.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
8 changes: 8 additions & 0 deletions Answers/40230112119/.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/40230112119/.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/40230112119/.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/40230112119/.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/40230112119/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>dfghjk</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>
17 changes: 17 additions & 0 deletions Answers/40230112119/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.example;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");

for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}
}
}
43 changes: 43 additions & 0 deletions Answers/40230112119/src/main/java/org/example/Match.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.example;

public class Match {
Team team1;
Team team2;
public Match(Team team1, Team team2) {
this.team1 = team1;
this.team2 = team2;
}
public void start() {
int team1score = team1.numGoals;
int team2score = team2.numGoals;

for (int i = 0; i < 100; i++) {
team1.play();
if (team1.seeker.isSuccessful()) {
team1score += 150;
break;
}
team2.play();
if (team2.seeker.isSuccessful()) {
team2score += 150;
break;
}
}
for (int i = 0; i < team1.numGoals; i++) {
team1score += 10;
}
for (int i = 0; i < team2.numGoals; i++) {
team2score += 10;
}

System.out.println("Team one score: " + team1score);
System.out.println("Team two score: " + team2score);
if (team1score > team2score)
System.out.println("TEAM ONE WINS!!!");
else if (team1score < team2score)
System.out.println("TEAM TWO WINS!!!");
else
System.out.println("There's no winner!");
}

}
22 changes: 22 additions & 0 deletions Answers/40230112119/src/main/java/org/example/MyApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.example;

public class MyApp {
public static void main(String[] args) {
int goals1 = 0;
int goals2 = 0;
Keeper keeper1 = new Keeper("Harry", 1);
Seeker seeker1 = new Seeker("Ron", 2);
Chaser[] chasers1 = {new Chaser("Ginny", 3), new Chaser("Katie", 4), new Chaser("Angelina", 5)};
Beater[] beaters1 = {new Beater("Oliver", 6), new Beater("Fred", 7)};
Team team1 = new Team(keeper1, seeker1, chasers1, beaters1, goals1);

Keeper keeper2 = new Keeper("Draco", 1);
Seeker seeker2 = new Seeker("Marcus", 2);
Chaser[] chasers2 = {new Chaser("Adrian", 3), new Chaser("Vincent", 4), new Chaser("Trence", 5)};
Beater[] beaters2 = {new Beater("Miles", 6), new Beater("Andrew", 7)};
Team team2 = new Team(keeper1, seeker1, chasers1, beaters1, goals2);

Match match = new Match(team1, team2);
match.start();
}
}
51 changes: 51 additions & 0 deletions Answers/40230112119/src/main/java/org/example/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.example;
import java.util.Random;

public abstract class Player implements Success {
String name;
int num;
public Player(String name, int num) {
this.name = name;
this.num = num;
}
}
class Keeper extends Player {
public Keeper(String name, int num) {
super(name, num);
}
@Override
public boolean isSuccessful() {
Random random = new Random();
return random.nextInt(100) < 70;
}
}
class Seeker extends Player {
public Seeker(String name, int num) {
super(name, num);
}
@Override
public boolean isSuccessful() {
Random random = new Random();
return random.nextInt(100) < 5;
}
}
class Chaser extends Player {
public Chaser(String name, int num) {
super(name, num);
}
@Override
public boolean isSuccessful() {
Random random = new Random();
return random.nextInt(100) < 30;
}
}
class Beater extends Player {
public Beater(String name, int num) {
super(name, num);
}
@Override
public boolean isSuccessful() {
Random random = new Random();
return random.nextInt(100) < 40;
}
}
5 changes: 5 additions & 0 deletions Answers/40230112119/src/main/java/org/example/Success.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.example;

public interface Success {
public boolean isSuccessful();
}
40 changes: 40 additions & 0 deletions Answers/40230112119/src/main/java/org/example/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.example;

public class Team {
Keeper keeper;
Seeker seeker;
Chaser[] chasers;
Beater[] beaters;
int numGoals;
public Team(Keeper keeper, Seeker seeker, Chaser[] chasers, Beater[] beaters, int numGoals) {
this.keeper = keeper;
this.seeker = seeker;
this.chasers = chasers;
this.beaters = beaters;
this.numGoals = 0;
}
private void setGoal() {
this.numGoals++;
}
void play() {
boolean atleastOneBeater = false;
for (Beater beater : beaters) {
if (beater.isSuccessful()) {
atleastOneBeater = true;
break;
}
}
int successfulChasers = 0;
boolean atleastTwoChasers = false;
for (Chaser chaser : chasers) {
if (chaser.isSuccessful())
successfulChasers++;
}
if (successfulChasers >= 2)
atleastTwoChasers = true;

if (keeper.isSuccessful() && atleastOneBeater && atleastTwoChasers)
setGoal();
}
}