Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void analyzeVowelConsonantContentOfWordPhrase(String Input)
- {
- String result = "";
- String userInput = Input.toLowerCase();
- char[] testInput = userInput.toCharArray();
- String[] test = new String[testInput.length];
- for(int j = 0 ; j < testInput.length ; j++)
- {
- char holder = testInput[j];
- test[j] = Character.toString(holder);
- }
- String vowelPattern = "a|e|i|o|u";
- String aPattern = "a";
- String ePattern = "e";
- String iPattern = "i";
- String oPattern = "o";
- String uPattern = "u";
- boolean onlyConsonants = true;
- boolean allVowels = false;
- boolean vowelsOrder = false;
- boolean vowelsBackwards = false;
- int countA = 0;
- int countE = 0;
- int countI = 0;
- int countO = 0;
- int countU = 0;
- int indexA;
- int indexE;
- int indexI;
- int indexO;
- int indexU;
- String consonants = "bcdfghjklmnpqrstvwxyz";
- int[] count = new int[21];
- String[] conOutput = {"B","C","D","F","G","H","J","K","L","M","N","P","Q","R","S","T","V","W","X","Y","Z"};
- String aChar;
- int position;
- String tempInput = userInput.replaceAll("[^a-zA-Z]","");
- String r = "\nConsonant count:";
- for(int i = 0 ; i < tempInput.length() ; i++)
- {
- aChar = tempInput.substring(i, i+1);
- position = consonants.indexOf(aChar);
- if(position != -1)
- count[position]++;
- }
- for(int j = 0 ; j < consonants.length() ; j++)
- {
- if(count[j] != 0)
- r += "\n" + conOutput[j] + " occurs " + count[j] + " time( s)";
- }
- for(int j = 0 ; j < testInput.length ; j++)
- {
- if(test[j].matches(vowelPattern))
- onlyConsonants = false;
- }
- for(int j = 0 ; j < testInput.length ; j++)
- {
- if(test[j].matches(aPattern))
- countA++;
- else if(test[j].matches(ePattern))
- countE++;
- else if(test[j].matches(iPattern))
- countI++;
- else if(test[j].matches(oPattern))
- countO++;
- else if(test[j].matches(uPattern))
- countU++;
- }
- if(countA >= 1 && countE >= 1 && countI >= 1 && countO >= 1 && countU >= 1)
- {
- allVowels = true;
- indexA = Input.indexOf('a');
- indexE = Input.indexOf('e');
- indexI = Input.indexOf('i');
- indexO = Input.indexOf('o');
- indexU = Input.indexOf('u');
- if(((indexA < indexE)&&(indexE < indexI)&&(indexI < indexO)&&(indexO < indexU)) && ((countA == 1)&&(countE == 1)&&(countI == 1)&&(countO == 1)&&(countU == 1)))
- vowelsOrder = true;
- else if(((indexA > indexE)&&(indexE > indexI)&&(indexI > indexO)&&(indexO > indexU)) && ((countA == 1)&&(countE == 1)&&(countI == 1)&&(countO == 1)&&(countU == 1)))
- vowelsBackwards = true;
- }
- if(onlyConsonants)
- result += "Input contains no vowels";
- else if(vowelsOrder)
- result += "Input contains all vowels in alphabetical order\nVowel count:";
- else if(vowelsBackwards)
- result += "Input contains all vowels in reverse alphabetical order\nVowel count:";
- else if(allVowels)
- result += "Input contains all vowels in any order\nVowel count:";
- else
- result += "Input contains vowels and consonants but not all vowels\nVowel count:";
- if(countA >= 1)
- result += "\n A occurs " + countA + " time(s)";
- if(countE >= 1)
- result += "\n E occurs " + countE + " time(s)";
- if(countI >= 1)
- result += "\n I occurs " + countI + " time(s)";
- if(countO >= 1)
- result += "\n O occurs " + countO + " time(s)";
- if(countU >= 1)
- result += "\n U occurs " + countU + " time(s)";
- result += r;
- JOptionPane.showMessageDialog(null, result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement