-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.java
48 lines (38 loc) · 1.18 KB
/
Helper.java
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
42
43
44
45
46
47
48
import java.security.SecureRandom;
public class Helper
{
public static int translateABCDToNumber(String coord)
{
String[] letters = {"A", "B", "C", "D"};
String letterToTranslate = coord.substring(0).toLowerCase();
int xCoord = 0;
Debug.log("Letter given: " + coord + ", "
+ "letter to translate: " + letterToTranslate);
for (int i = 0; i < letters.length; i++)
{
boolean match = (letterToTranslate.matches(letters[i].toLowerCase()));
Debug.log("Letter in loop: " + letters[i] + ", "
+ "match?: " + match);
if (letterToTranslate.matches(letters[i].toLowerCase())) {
xCoord = i;
}
}
Debug.log("Translated to coordinate: " + xCoord);
return xCoord;
}
public static String translateNumberToABCD(int x, int y)
{
String[] letters = {"A", "B", "C", "D"};
String xCoord = letters[x];
String yCoord = Integer.toString(y + 1);
String coord = xCoord + yCoord;
return coord;
}
public static int generateRandomNumber(int max)
{
SecureRandom randomGenerator = new SecureRandom();
int randomNumber;
randomNumber = randomGenerator.nextInt(max);
return randomNumber;
}
}