We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent eebfb33 commit 3269ec8Copy full SHA for 3269ec8
src/main/java/RandomStringChooser.java
@@ -2,7 +2,24 @@
2
public class RandomStringChooser
3
{
4
/* to be implemented in part (a) */
5
-
6
- //Heads up!
7
- //You will get a very confusing error message until you have working code in part b as well
8
-}
+ private String[] words;
+ private int numsleft;
+ public RandomStringChooser(String[] wordArray){
+ words = new String[wordArray.length];
9
+
10
+ for(int i=0; i<wordArray.length; i++){
11
+ words[i] = wordArray[i];
12
+ }
13
+ numsleft = words.length;
14
15
+ public String getNext() {
16
+ if(numsleft==0){
17
+ return "NONE";
18
19
+ int index= (int)(Math.random()*numsleft);
20
+ String selected = words[index];
21
+ words[index] = words[numsleft-1];
22
+ numsleft--;
23
+ return selected;
24
25
0 commit comments