Compare commits

...

2 Commits

Author SHA1 Message Date
2369958a2e started 2025ft 2026-05-12 14:29:51 +02:00
9ec4ee6c5b added finished tests to Readme 2026-05-12 12:08:23 +02:00
8 changed files with 120 additions and 1 deletions

View File

@@ -1 +1,3 @@
# OOP Klausuren der vergangenen Jahre
- 2025 ST
- 2025 FT

9
src/j2025/FT/Die.java Normal file
View File

@@ -0,0 +1,9 @@
package j2025.FT;
public enum Die {
ONE, TWO, THREE, FOUR, FIVE, SIX;
public static Die random() {
return values()[(int) (Math.random() * 6)];
}
}

5
src/j2025/FT/Game.java Normal file
View File

@@ -0,0 +1,5 @@
package j2025.FT;
public class Game {
}

View File

@@ -0,0 +1,36 @@
package j2025.FT;
public class PairOfDice implements Comparable<PairOfDice> {
private final Die die1;
private final Die die2;
public PairOfDice(Die die1, Die die2) {
this.die1 = die1;
this.die2 = die2;
}
@Override
public int compareTo(PairOfDice other) {
return Integer.compare(this.getValue(), other.getValue());
}
private int getValue() {
int high = Math.max(die1.ordinal(), die2.ordinal());
int low = Math.min(die1.ordinal(), die2.ordinal());
// Mäxchen (2,1) → höchster Wert
if (high == 2 && low == 1) return Integer.MAX_VALUE;
// Pasch → 100 + Augenzahl (11..66 → 101..106)
if (high == low) return 100 + high;
// Normale Würfe → zweistellige Zahl (z.B. 6,5 → 65)
return high * 10 + low;
}
public static PairOfDice random() {
return new PairOfDice(Die.random(), Die.random());
}
}

View File

@@ -0,0 +1,21 @@
package j2025.FT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class PairOfDiceTest {
private final PairOfDice p33 = new PairOfDice(Die.THREE, Die.THREE);
private final PairOfDice p41 = new PairOfDice(Die.FOUR, Die.ONE);
@Test
public void testCompareTo() {
// p33 ist Pasch → Wert 102, p41 → Wert 41: p33 > p41
assertTrue(p33.compareTo(p41) > 0);
assertTrue(p41.compareTo(p33) < 0);
assertEquals(0, p33.compareTo(p33));
assertEquals(0, p41.compareTo(p41));
}
}

24
src/j2025/FT/Player.java Normal file
View File

@@ -0,0 +1,24 @@
package j2025.FT;
public class Player {
private final String name;
private int points = 0;
public Player(String name, int points) {
this.name = name;
this.points = points;
}
public int getPoints() {
return points;
}
public String getName() {
return name;
}
public void losesPoint() {
points--;
}
}

View File

@@ -0,0 +1,17 @@
package j2025.FT;
import java.util.LinkedList;
import java.util.List;
public class PlayerHandler {
private List<Player> players = new LinkedList<>();
public void addPlayer(Player player) {
players.add(player);
}
public Player getCurrentPlayer() {
return players.getFirst();
}
}

5
src/j2025/FT/State.java Normal file
View File

@@ -0,0 +1,5 @@
package j2025.FT;
public class State {
}