praktikum1/aufgabe3

This commit is contained in:
2026-04-17 11:08:20 +02:00
parent 9edd9ebaeb
commit 5b4e30baaa
4 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
package org.example.demo.praktikum1.aufgabe3;
public enum GuessResult {
TooSmall,
TooBig,
Success,
}

View File

@@ -0,0 +1,25 @@
package org.example.demo.praktikum1.aufgabe3;
import java.util.Random;
import jakarta.ejb.Stateful;
@Stateful
public class GuessingGame implements GuessingGameRemote {
private int num;
public void init() {
var rng = new Random();
num = 1 + rng.nextInt(0, 100);
}
public GuessResult testGuess(int guess) {
if (guess < num) {
return GuessResult.TooSmall;
}
if (guess > num) {
return GuessResult.TooBig;
}
return GuessResult.Success;
}
}

View File

@@ -0,0 +1,11 @@
package org.example.demo.praktikum1.aufgabe3;
import jakarta.ejb.Remote;
@Remote
public interface GuessingGameRemote {
// start ein spiel, generiere ein zufallszahl.
void init();
// test whether the guess is correct.
GuessResult testGuess(int guess);
}