diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 0000000..bfbeb0d --- /dev/null +++ b/.devcontainer.json @@ -0,0 +1,3 @@ +{ + "image": "mcr.microsoft.com/devcontainers/java:21" +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..add4f4e --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "vscjava.vscode-java-pack" + ] +} \ No newline at end of file diff --git a/Club.java b/Club.java new file mode 100644 index 0000000..fc250dd --- /dev/null +++ b/Club.java @@ -0,0 +1 @@ +public record Club(String name, int marketValueInMillions) {} diff --git a/Exercise.java b/Exercise.java index 3c092f9..c2b0a04 100644 --- a/Exercise.java +++ b/Exercise.java @@ -1,6 +1,14 @@ +import java.util.ArrayList; + public class Exercise { public static void main(String[] args) { - // implement exercise here + Tournament tournament = new Tournament("Football Cup", new ArrayList<>(), new ArrayList<>()); + + tournament.addClub(new Club("SC Freiburg", 165)); + tournament.addClub(new Club("Bayern Muenchen", 926)); + tournament.addClub(new Club("Borussia Dortmund", 462)); + + tournament.pairs().forEach(System.out::println); } } diff --git a/Pair.java b/Pair.java new file mode 100644 index 0000000..40a05c6 --- /dev/null +++ b/Pair.java @@ -0,0 +1 @@ +public record Pair(T partA, T partB) {} diff --git a/Tournament.java b/Tournament.java new file mode 100644 index 0000000..51eebc1 --- /dev/null +++ b/Tournament.java @@ -0,0 +1,20 @@ +import java.util.List; + +public record Tournament(String title, List clubs, List> pairs) { + + public void addClub(Club club) { + clubs.add(club); + } + + public List> pairs() { + for (int i = 0; i < clubs.size(); i++) { + for (int j = 0; j < clubs.size(); j++) { + if (i != j) { + pairs.add(new Pair(clubs.get(i), clubs.get(j))); + } + } + } + + return pairs; + } +}