|
| 1 | +# Instructions |
| 2 | + |
| 3 | +Mary is a big fan of the TV series _Star Trek: The Next Generation_. |
| 4 | +She often plays pen-and-paper role playing games, where she and her friends pretend to be the crew of the _Starship Enterprise_. |
| 5 | +Mary's character is Captain Picard, which means she has to keep the captain's log. |
| 6 | +She loves the creative part of the game, but doesn't like to generate random data on the spot. |
| 7 | + |
| 8 | +Help Mary by creating random generators for data commonly appearing in the captain's log. |
| 9 | + |
| 10 | +~~~~exercism/note |
| 11 | +The starter implementation of this exercise takes a `java.util.Random` instance as constructor argument. |
| 12 | +This allows the exercise's tests to pass an instance with a predefined seed, which makes the test results predictable. |
| 13 | +
|
| 14 | +Therefore, you are expected to use provided the `java.util.Random` instance in your implementation. |
| 15 | +~~~~ |
| 16 | + |
| 17 | +## 1. Generate a random planet |
| 18 | + |
| 19 | +The _Starship Enterprise_ encounters many planets in its travels. |
| 20 | +Planets in the Star Trek universe are split into categories based on their properties. |
| 21 | +For example, Earth is a class `M` planet. |
| 22 | +All possible planetary classes are: `D`, `H`, `J`, `K`, `L`, `M`, `N`, `R`, `T`, and `Y`. |
| 23 | + |
| 24 | +Implement the `randomPlanetClass()` method. |
| 25 | +It should return one of the planetary classes at random. |
| 26 | + |
| 27 | +```java |
| 28 | +captainsLog.randomPlanetClass(); |
| 29 | +// => "K" |
| 30 | +``` |
| 31 | + |
| 32 | +## 2. Generate a random starship registry number |
| 33 | + |
| 34 | +Enterprise (registry number `NCC-1701`) is not the only starship flying around! |
| 35 | +When it rendezvous with another starship, Mary needs to log the registry number of that starship. |
| 36 | + |
| 37 | +Registry numbers start with the prefix "NCC-" and then use a number from `1000` to `9999` (inclusive). |
| 38 | + |
| 39 | +Implement the `randomShipRegistryNumber()` method that returns a random starship registry number. |
| 40 | + |
| 41 | +```java |
| 42 | +captainsLog.randomShipRegistryNumber(); |
| 43 | +// => "NCC-1947" |
| 44 | +``` |
| 45 | + |
| 46 | +## 3. Generate a random stardate |
| 47 | + |
| 48 | +What's the use of a log if it doesn't include dates? |
| 49 | + |
| 50 | +A stardate is a floating point number. |
| 51 | +The adventures of the _Starship Enterprise_ from the first season of _The Next Generation_ take place between the stardates `41000.0` and `42000.0`. |
| 52 | +The "4" stands for the 24th century, the "1" for the first season. |
| 53 | + |
| 54 | +Implement the `randomStardate()` method that returns a floating point number between `41000.0` (inclusive) and `42000.0` (exclusive). |
| 55 | + |
| 56 | +```java |
| 57 | +captainsLog.randomStardate(); |
| 58 | +// => 41458.15721310934 |
| 59 | +``` |
0 commit comments