+/EE422C

software design

git clone https://git.julia.blue/+/EE422C

Joseph RyanAdd the rest of the files7e47727

master
936 B32 linesraw
1package assignment2;
2
3import java.util.Random;
4
5public class SecretCodeGenerator {
6
7    private static SecretCodeGenerator instance = new SecretCodeGenerator();
8
9    private Random randomGenerator;
10
11    public static SecretCodeGenerator getInstance() {
12        return instance;
13    }
14
15    // Do not create your own SecretCodeGenerator Objects
16    private SecretCodeGenerator() {
17        randomGenerator = new Random();
18    }
19
20    // Use this method for each game only once.
21    // The correct way to call this is: SecretCodeGenerator.getInstance().getNewSecretCode()
22    public String getNewSecretCode() {
23        String result = "";
24        int index, numberOfPegs = GameConfiguration.pegNumber;
25        String[] colors = GameConfiguration.colors;
26        for (int i = 0; i < numberOfPegs; i++) {
27            index = randomGenerator.nextInt(colors.length);
28            result += colors[index];
29        }
30        return result;
31    }
32}