The goal of the program is to return words from a list of words that have all 6 vowels (including y). Where are the vowels in alphabetical order. For example, the answer might be something like: Aerious (Aerious doesn't work, although it doesn't have y). Currently, the program does not return any words. I do not think the containsVowels method is correct.
public static void question11() { System.out.println("Question 11:"); System.out.println("All words that have 6 vowels once in alphabetical order: "); String vowelWord = ""; for(int i = 1; i< WordList.numWords(); i++) { if(containsVowels(WordList.word(i))) { if(alphabetical(WordList.word(i))) { vowelWord = WordList.word(i); System.out.println(vowelWord); } } } return; } public static boolean alphabetical(String word) { int vowelPlaceA = 0; int vowelPlaceE = 0; int vowelPlaceI = 0; int vowelPlaceO = 0; int vowelPlaceU = 0; int vowelPlaceY = 0; for(int i = 0; i < word.length(); i++) { if (word.charAt(i) == 'a') { vowelPlaceA = i; } if (word.charAt(i) == 'e') { vowelPlaceE = i; } if (word.charAt(i) == 'i') { vowelPlaceI = i; } if (word.charAt(i) == 'o') { vowelPlaceO = i; } if (word.charAt(i) == 'u') { vowelPlaceU = i; } if (word.charAt(i) == 'y') { vowelPlaceY = i; } //check a alphabetical if(vowelPlaceA > vowelPlaceE || vowelPlaceA > vowelPlaceI || vowelPlaceA > vowelPlaceO || vowelPlaceA > vowelPlaceU || vowelPlaceA > vowelPlaceY) { return false; } //check e alphabetical if(vowelPlaceE > vowelPlaceI || vowelPlaceE > vowelPlaceO || vowelPlaceE > vowelPlaceU || vowelPlaceE > vowelPlaceY) { return false; } //i if(vowelPlaceI > vowelPlaceO || vowelPlaceI > vowelPlaceU || vowelPlaceI > vowelPlaceY) { return false; } //o if(vowelPlaceO > vowelPlaceU || vowelPlaceO > vowelPlaceY) { return false; } //u if(vowelPlaceU > vowelPlaceY) { return false; } } return true; } public static boolean containsVowels(String word) { String vowels = "aeiouy"; if (word.contains(vowels)) { return true; } return false; }
Timmy source share