import java.util.Scanner;
class WordTest1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
WordGen.initialise(input);
System.out.print("Enter the number of words you wish to generate: ");
int n = input.nextInt();
WordStore words = new WordStore(n);
for(int i=0; i<n; i++)
words.add(WordGen.make());
String line = input.nextLine();
System.out.println("Enter words to test, empty line to exit");
line = input.nextLine();
while(!line.equals(""))
{
String[] wordlist = line.split(" ");
for(int i=0; i<wordlist.length; i++)
{
int count = words.count(wordlist[i]);
System.out.print("\""+wordlist[i]+"\" ");
if(count==0)
System.out.println("NOT generated");
else if(count==1)
System.out.println("generated once");
else
System.out.println("generated "+count+" times ");
}
line = input.nextLine();
}
}
}
import java.util.*;
class WordStore
{
public int a = 0;
public WordStore(int n){
a = n;
}
public String[] storewords = new String[a];
public int count=0;
public void add(String word){
storewords[count] = word;
count=count+1;
}
}
WordGen.java just cretaes random words
Why do i get an ArrayIndexOutOfBounds Exception: 0
at WordStore.add(WordStore.java:20)
at WordTest1.main(WordTest1.java:13)
U cant change the code in WordTest1.java, but can change WordStore.java, but add method has to be declared
public void add(String word)