As usual Arrays and their lists will be the death of me, only this time the lab is working just fine up until the End and then i get a strong error, and me being a java newbie have know idea what this is. hopefully some of you better programmers will be able to help me.
Error + current output.
word with 2 vowels = 5
word with 3 vowels = 0
word with 4 vowels = 1
word with 2 chars = 0
word with 3 chars = 3
word with 4 chars = 2
word with 5 chars = 2
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
at java.util.ArrayList$Itr.next(ArrayList.java:851)
at Words.removeWordsWithXChars(Words.java:54)
at Lab16c.main(Lab16c.java:25)
output i want
[one, two, three, four, five, six, seven, alligator]
word with 2 vowels = 5
word with 3 vowels = 0
word with 4 vowels = 1
word with 2 chars = 0
word with 3 chars = 3
word with 4 chars = 2
word with 5 chars = 2
after removing words with 3 chars
[three, four, five, seven, alligator]
number of vowels in the words removed == 4
code in main
public class Lab16c
{
public static void main( String args[] )
{
Words test = new Words("one two three four five six seven alligator");
out.println(test);
out.println("word with 2 vowels = "+test.countWordsWithXVowels(2));
out.println("word with 3 vowels = "+test.countWordsWithXVowels(3));
out.println("word with 4 vowels = "+test.countWordsWithXVowels(4));
out.println("word with 2 chars = "+test.countWordsWithXChars(2));
out.println("word with 3 chars = "+test.countWordsWithXChars(3));
out.println("word with 4 chars = "+test.countWordsWithXChars(4));
out.println("word with 5 chars = "+test.countWordsWithXChars(5));
int vowelsRemoved = test.removeWordsWithXChars(3);
out.println("\nafter removing words with 3 chars \n" + test);
out.println("\nnumber of vowels in the words removed == " + vowelsRemoved);
out.println("\n\n");
//more test cases
}
}
code in third class public int countWordsWithXChars(int size) { int count=0; for(Word i : words) { if(i.getLength() == size) { count++; } } return count; }
//this method will remove all words with a specified size / length
//this method will also return the sum of the vowels in all words removed
public int removeWordsWithXChars(int size)
{
for(Word i : words)
{
if(i.getLength() == size)
{
words.remove(i);
}
}
return 0;
}
public int countWordsWithXVowels(int numVowels)
{
int count=0;
for(Word i: words)
{
if(i.getNumVowels() == numVowels)
{
count++;
}
}
return count;
}
public String toString()
{
return "";
}
}
hopefully you can find my problem , thanks in the future