forked from exercism/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobot.java
More file actions
41 lines (32 loc) · 952 Bytes
/
Robot.java
File metadata and controls
41 lines (32 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.Random;
public class Robot {
private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private String name;
private final Random random;
public Robot() {
random = new Random();
assignNewName();
}
private void assignNewName() {
name = String.format("%s%d", prefix(), suffix());
}
public String getName() {
return name;
}
public void reset() {
assignNewName();
}
private String prefix() {
return String.format("%c%c",
getRandomCharacterFromAlphabet(),
getRandomCharacterFromAlphabet());
}
private char getRandomCharacterFromAlphabet() {
return ALPHABET.charAt(random.nextInt(ALPHABET.length()));
}
private int suffix() {
final int low = 100;
final int high = 999;
return random.nextInt(high - low - 1) + low;
}
}