praktikum1/aufgabe3
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package org.example.demo.praktikum1.aufgabe3;
|
||||
|
||||
public enum GuessResult {
|
||||
TooSmall,
|
||||
TooBig,
|
||||
Success,
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user