Merge pull request #78 from Weltenbummler397/exercism-sync/dd600d97a1915411

[Sync Iteration] java/captains-log/1
This commit is contained in:
Weltenbummler397 2026-05-04 09:55:35 +02:00 committed by GitHub
commit 34b5425e71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,30 @@
import java.util.Random;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
class CaptainsLog {
private static final char[] PLANET_CLASSES = new char[]{'D', 'H', 'J', 'K', 'L', 'M', 'N', 'R', 'T', 'Y'};
private Random random;
CaptainsLog(Random random) {
this.random = random;
}
char randomPlanetClass() {
List<Character> buchstaben = List.of('D', 'H', 'J', 'K', 'L', 'M', 'N', 'R', 'T', 'Y');
int index = random.nextInt(buchstaben.size());
return buchstaben.get(index);
}
String randomShipRegistryNumber() {
int zahl = random.nextInt(10000 - 1000) + 1000;
return "NCC-" + zahl;
}
double randomStardate() {
return 41000 +random.nextDouble() * (42000 - 41000);
}
}