diff --git a/uebung04/tournament/ByeGame.java b/uebung04/tournament/ByeGame.java index c8d59a6..2de0ad6 100644 --- a/uebung04/tournament/ByeGame.java +++ b/uebung04/tournament/ByeGame.java @@ -8,7 +8,7 @@ public class ByeGame extends Game{ private final String player1; private final Game ref; - ByeGame(String player1, Game ref){ + ByeGame(String player1, Game ref) { super(); this.ref = ref; this.player1 = player1; @@ -38,8 +38,7 @@ public class ByeGame extends Game{ @Override - public List getAllGames() - { + public List getAllGames() { List temp = new ArrayList<>(); temp.add(this); temp.addAll(ref.getAllGames()); diff --git a/uebung04/tournament/Game.java b/uebung04/tournament/Game.java index 47e6170..6f7c939 100644 --- a/uebung04/tournament/Game.java +++ b/uebung04/tournament/Game.java @@ -3,25 +3,26 @@ package tournament; import java.util.List; public abstract class Game { - private static int counter = 0; - protected final int id; - //null nicht notwendig - protected String winner = null; + + private static int counter = 0; + protected final int id; + //null nicht notwendig + protected String winner = null; - protected Game() { - this.id = counter++; - } + protected Game() { + this.id = counter++; + } - public int getId(){ - return this.id; - } + public int getId(){ + return this.id; + } - public String getWinner(){ - return this.winner; - } + public String getWinner(){ + return this.winner; + } - public void setWinner(String winner) { + public void setWinner(String winner) { if (this.winner != null) throw new IllegalStateException("winner already set"); if (getPlayer1() == null || getPlayer2() == null) @@ -33,19 +34,18 @@ public abstract class Game { } - public abstract String getPlayer1(); + public abstract String getPlayer1(); - public abstract String getPlayer2(); + public abstract String getPlayer2(); - public abstract List getAllPlayers(); + public abstract List getAllPlayers(); public abstract List getRemaningPlayers(); public abstract List getAllGames(); - public String toString(){ - return "Game: " + getId() + " Player: "+ getPlayer1()+ " vs Player: " + getPlayer2() + "Winner is: "+ getWinner(); - } - + public String toString() { + return "Game: " + getId() + " Player: "+ getPlayer1()+ " vs Player: " + getPlayer2() + "Winner is: "+ getWinner(); + } } diff --git a/uebung04/tournament/OrdinaryGame.java b/uebung04/tournament/OrdinaryGame.java index 1ba43e4..afbf8b9 100644 --- a/uebung04/tournament/OrdinaryGame.java +++ b/uebung04/tournament/OrdinaryGame.java @@ -5,45 +5,46 @@ import java.util.Arrays; import java.util.List; public class OrdinaryGame extends Game{ + private Game Player1; private Game Player2; - public OrdinaryGame(Game Player1, Game Player2) - { + + public OrdinaryGame(Game Player1, Game Player2) { this.Player1 = Player1; this.Player2 = Player2; } + @Override - public String getPlayer1() - { + public String getPlayer1() { return Player1.getWinner(); } + @Override - public String getPlayer2() - { + public String getPlayer2() { return Player2.getWinner(); } + @Override - public List getAllPlayers() - { - List temp = new ArrayList(); + public List getAllPlayers() { + List temp = new ArrayList<>(); temp.addAll(Player1.getAllPlayers()); temp.addAll(Player2.getAllPlayers()); return temp; } + @Override - public List getRemaningPlayers() - { + public List getRemaningPlayers() { if(this.getWinner() != null) return new ArrayList<>(Arrays.asList(this.getWinner())); - List temp = new ArrayList(); + List temp = new ArrayList<>(); temp.addAll(Player1.getRemaningPlayers()); temp.addAll(Player2.getRemaningPlayers()); return temp; } + @Override - public List getAllGames() - { - List temp = new ArrayList(Arrays.asList(this.getId())); + public List getAllGames() { + List temp = new ArrayList<>(); temp.addAll(Player1.getAllGames()); temp.addAll(Player2.getAllGames()); return temp; diff --git a/uebung04/tournament/SeededGame.java b/uebung04/tournament/SeededGame.java index c39f5c9..5d816cf 100644 --- a/uebung04/tournament/SeededGame.java +++ b/uebung04/tournament/SeededGame.java @@ -6,6 +6,7 @@ import java.util.Arrays; import java.util.List; public class SeededGame extends Game{ + private String player1; private String player2; @@ -16,35 +17,32 @@ public class SeededGame extends Game{ } @Override - public String getPlayer1() - { + public String getPlayer1() { return player1; } @Override - public String getPlayer2() - { + public String getPlayer2() { return player2; } @Override - public List getAllPlayers() - { + public List getAllPlayers() { //return new ArrayList(Arrays.asList(player1, player2)); return List.of(player1, player2); } @Override - public List getRemaningPlayers() - { - if(this.getWinner() != null) + public List getRemaningPlayers() { + if(this.getWinner() != null) { return new ArrayList<>(Arrays.asList(this.getWinner())); - List temp = new ArrayList(Arrays.asList(player1,player2)); - return temp; + } + + return List.of(player1, player2); } + @Override - public List getAllGames() - { + public List getAllGames() { return List.of(this); } }