Haiku detector. Write a program that reads in text from standard input and checks whether it forms a haiku. A haiku consists of three lines containing the correct number of syllables (5, 7, and 5,...

Haiku detector. Write a program that reads in text from standard input and checks whether it forms a haiku. A haiku consists of three lines containing the correct number of syllables (5, 7, and 5, respectively). For the purpose of this problem, define a syllable to be any contiguous sequence of consecutive vowels (a, e, i, o, u, or y). According to this rule, haiku has two syllables and purpose has three syllables. Of course, the second example is wrong since the e in purpose is silent. here is my code, I cannot figure out why the haikuCheck never increments the count. public class HaikuDetector { public static int haikuCheck(String line) { int count = 0; String vowels = "a, e, i, o, u, y"; String vNoE = "a, i, o, u, y"; String[] a = line.split(""); for (int i = 0; i a[i] = a[i].toLowerCase(); // increment if the adjacent char are not vowel for (int j = 1; j char c1 = a[i].charAt(j - 1); char c = a[i].charAt(j); if (vowels.indexOf(c) >= 0 && vowels.indexOf(c1) == -1) { count++; } // Check the first and last char char first = a[i].charAt(0); char last = a[i].charAt(a[i].length() - 1); if (vNoE.indexOf(last) >= 0) { count++; } if (vowels.indexOf(first) >= 0) { count++; } // if none there is one! if (count count++; } } } return count; } public static void main(String[] args) { while (!StdIn.isEmpty()) { String line1 = StdIn.readLine(); String line2 = StdIn.readLine(); String line3 = StdIn.readLine(); boolean isL1aHaiku = false; boolean isL2aHaiku = false; boolean isL3aHaiku = false; int linea = HaikuDetector.haikuCheck(line1); System.out.println("line 1 is: " + line1 + " The Count is: " + linea); int lineb = HaikuDetector.haikuCheck(line2); System.out.println("line 2 is: " + line2 + " The Count is: " + lineb); int linec = HaikuDetector.haikuCheck(line3); System.out.println("line 1 is: " + line3 + " The Count is: " + linec); if (linea == 5) isL1aHaiku = true; if (lineb == 7) isL2aHaiku = true; if (linec == 5) isL3aHaiku = true; if (isL1aHaiku && isL2aHaiku && isL3aHaiku) { System.out.println(" Poem is a Haiku"); } else System.out.println(" Poem is NOT a Haiku"); } } } Here is my output from the terminal window: java-introcs HaikuDetector line 1 is: I am first with five The Count is: 0 line 2 is: Then seven in the middle The Count is: 0 line 1 is: Five again to end The Count is: 0 Poem is NOT a Haiku
May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here