The problem is as follows: 6 words are to be displayed on the screen. These words are chosen at random from a list. When I wrote the code, I didn't get any error, but when I ran it in eclipse, I got the following gibberish result in the console "package.wordsContainer@659e0bfd".
What did I do wrong?
public class wordsContainer {
Collection<String> wordList = new ArrayList<String>();
public void wordGroup1() {
wordList.add("Ant");
wordList.add("Almond");
wordList.add("Atom");
wordList.add("Affair");
wordList.add("Ample");
wordList.add("Blue");
wordList.add("Black");
wordList.add("Bronze");
wordList.add("Beauty");
wordList.add("Beautiful");
wordList.add("Batter");
wordList.add("Crazy");
}
public Collection<String> getRandomWords() {
wordGroup1();
LinkedList<String> wordLinkedList = new LinkedList<String>(wordList);
ArrayList<String> subList = new ArrayList<String>();
int i = 0;
while (i < 6) {
int index = (int) Math.random() * 10;
if (!subList.contains(wordLinkedList.get(index))) {
subList.add(wordLinkedList.get(index));
i++;
}
}
return subList;
}
}
public class wordsContainerTest {
public static void main(String[] args) {
wordsContainer list1 = new wordsContainer();
list1.wordGroup1();
System.out.println(list1);
System.out.println(list1.getRandomWords());
}
}