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