mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-05-15 17:58:44 +00:00
Merge pull request #78 from Weltenbummler397/exercism-sync/dd600d97a1915411
[Sync Iteration] java/captains-log/1
This commit is contained in:
commit
34b5425e71
30
solutions/java/captains-log/1/src/main/java/CaptainsLog.java
Normal file
30
solutions/java/captains-log/1/src/main/java/CaptainsLog.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user