Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  haha
Language: JAVA
Code:
public class VowelCons 
        {
    private final String str;
    private final int totalConsonants;
    private final int totalVowels;

        public VowelCons(final String s) 
    {
             this.str = s;
                int totalConsonants = 0;
                int totalVowels = 0;
                if (null != s) 
        {
                    for (final char c : s.toCharArray()) 
            {
                                switch (c) 
                    {
                                        case 'A':
                                        case 'a':
                                        case 'E':
                                        case 'e':
                                        case 'I':
                                        case 'i':
                                        case 'O':
                                        case 'o':
                                        case 'U':
                                        case 'u':

                        totalVowels++;
                                            break;

                        default:

                        if (Character.isLetter(c)) 
                        {
                                                    totalConsonants++;
                                            }
                                            break;
                                    }
                        }
                }
            this.totalConsonants = totalConsonants;
            this.totalVowels = totalVowels;
        }


    public String getString() 
    {
             return str;
    }

    public int getNumConsonants() 
    {
                return this.totalConsonants;
    }

    public int getNumVowels() 
    {
                return this.totalConsonants;
    }
}
Comments: