Question

In: Computer Science

Language is Java Design and write a Java console program to estimate the number of syllables...

Language is Java

Design and write a Java console program to estimate the number of syllables in an English word. Assume that the number of syllables is determined by vowels as follows. Each sequence of adjacent vowels (a, e, i, o, u, or y), except for a terminal e, is a syllable. However, the minimum number of syllables in an English word is one.

The program should prompt for a word and respond with the estimated number of syllables in that word. A run of the program should look exactly like this:

        Enter a word: hairy
        "hairy" has 2 syllables

Cannot use an array!!! Do NOT use continue or break!

My program accepts information fine, I'm just having trouble with the loop that counts how many syllables are in the string.

Solutions

Expert Solution

import java.util.*;

class Cnt

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

int s1 = 0;

int s2 = 0;

String word;

boolean count = false;

System.out.println("Enter a word: ");

word = sc.nextLine();

for (int i = 0; i < word.length(); i++)

{

String lower = word.toLowerCase();

char newC = lower.charAt(i);

if ((newC == 'a' || newC == 'e' || newC == 'u' || newC == 'y'|| newC == 'i' || newC == 'o') && 'e' != word.length() - 1)

{

s1 = s1 + 1;

if (!count)

{

count = true;

s1++;

System.out.println("\""+ word+"\" has "+ s1 + " syllables");

}

else if('e' == word.charAt(word.length()-1))

{

s2 = s2 + 1;

System.out.println("\""+ word+"\" has "+ s2 + " syllables");

}

}

}

}}


Related Solutions

program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to...
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to keep track of a student's current grade. You also get to design and write WeightedCourseGradeDriver class that requests input from the user and interacts with the WeightedCourseGrade class. Your WeightedCourseGrade class should store the following information: Weighted subtotal (the sum of all of the categories multiplied by the grade category weight) Total category weights (the sum of all the grade category weights) Provide the...
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1....
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods you...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps:...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
Write a Console Java program that inserts 25 random integers in the range of 0 to...
Write a Console Java program that inserts 25 random integers in the range of 0 to 100 into a Linked List. (Use SecureRandom class from java.security package. SecureRandom rand = new SecureRandom(); - creates the random number object rand.nextInt(100) - generates random integers in the 0 to 100 range) Using a ListItreator output the contents of the LinkedList in the reverse order. Using a ListItreator output the contents of the LinkedList in the original order.
Write a Console Java program that inserts 25 random integers in the range of 0 to...
Write a Console Java program that inserts 25 random integers in the range of 0 to 100 into a Linked List. (Use SecureRandom class from java.security package. SecureRandom rand = new SecureRandom(); - creates the random number object rand.nextInt(100) - generates random integers in the 0 to 100 range) Using a ListItreator output the contents of the LinkedList in the original order. Using a ListItreator output the contents of the LinkedList in the reverse order.
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that...
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and then display the following data: The lowest number in the array. The highest number in the array. The total of the numbers in the array. The average of the numbers in the array. PLEASE AND THANK YOU
Write a program to perform the following actions: the language is Java – Open an output...
Write a program to perform the following actions: the language is Java – Open an output file named “Assign14Numbers.txt” – Using a do-while loop, prompt the user for and input a count of the number of random integers to produce, make sure the value is between 35 and 150, inclusive. – After obtaining a good count, use a for-loop to generate the random integers in the range 0 ... 99, inclusive, and output each to the file as it is...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
Language: Java Design and implement a program that implements an Interpolation Search method. Interpolation search is...
Language: Java Design and implement a program that implements an Interpolation Search method. Interpolation search is similar to binary search, except it tries to begin the search nearer to the location of the item. Instead of the using the middle value of the sorted array, interpolation search estimates the location of the target with respect to the first & last values in the array. The implementation is the same as binary search except that you should calculate the mid value...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT