write a program to enter the string and do the following 1- count totle number of vowel 2- replace vowel 3- delete the charactor from given value 4- riverce the string 5- convert second word in upercase 6- convert third word in lowercase
hi friend,
Try the following code, may this will be helpful for you
index.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <head> <title>Index Page Example</title> </head> <body> <table> <tr> <td><h:link value="Get No Of Vowels" outcome="vowel" /></td> </tr> <tr> <td><h:link value="Get Reverse String" outcome="reverse" /></td> </tr> <tr> <td><h:link value="Change Character In Upper Case" outcome="upperText" /></td> </tr> <tr> <td><h:link value="Change Character In Lower Case" outcome="lowerText" /></td> </tr> <tr> <td><h:link value="Delete Character" outcome="delete" /></td> </tr> </table> </body> </html>
Continue...
vowel.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>Count Vowel Example</title> </h:head> <h:body> <h1>JSF Example</h1> <h:form id="form1"> <table> <tr> <td>Enter String To Check Vowel : </td> <td><h:inputText id="nameText" value="#{vowel.str}" required="true" requiredMessage="Field Mustn't Be Empty" tabindex="5" maxlength="15" accesskey="t"/></td> <td><h:message for="nameText" style="color:red" /></td> </tr> <tr> <td>Total No Of Vowels Are : </td> <td><h:outputText value="#{vowel.count}"/></td> </tr> <tr> <td><h:commandButton value="Get Vowel Count" action="#{vowel.getVowel(vowel.str)}" /></td> </tr> </table> </h:form> </h:body> </html>
Continue...
reverse.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>Reverse String Example</title> </h:head> <h:body> <h1>JSF Example</h1> <h:form id="form1"> <table> <tr> <td>Enter A String To Reverse : </td> <td><h:inputText id="text1" value="#{vowel.str}" required="true" requiredMessage="Field Mustn't Be Empty" tabindex="5" maxlength="15"/></td> <td><h:message for="text1" style="color:red" /></td> </tr> <tr> <td>New String After Reverse : </td> <td><h:outputText value="#{vowel.revString}"/></td> </tr> <tr> <td><h:commandButton value="Reverse Value" action="#{vowel.reverseString(vowel.str)}" /></td> </tr> </table> </h:form> </h:body> </html>
Continue...
upperText.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>Upper Text Example</title> </h:head> <h:body> <h1>JSF Example</h1> <h:form id="form1"> <table> <tr> <td>Enter A String To Convert In Upper Case <table> <tr> <td>(Second Word Should Be In Lower Case)</td> </tr> </table> </td> <td><h:inputText id="text1" value="#{vowel.str}" required="true" requiredMessage="Field Mustn't Be Empty" tabindex="5" maxlength="15"/></td> <td><h:message for="text1" style="color:red" /></td> </tr> <tr> <td>New String In Upper Case : </td> <td><h:outputText value="#{vowel.strUpper}"/></td> </tr> <tr> <td><h:commandButton value="Get Upper" action="#{vowel.upper(vowel.str)}" /></td> </tr> </table> </h:form> </h:body> </html>
Continue...
lowerText.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>Lower Text Example</title> </h:head> <h:body> <h1>JSF Example</h1> <h:form id="form1"> <table> <tr> <td>Enter A String To Convert In Lower Case <table> <tr> <td>(Third Word Should Be In Upper Case)</td> </tr> </table> </td> <td><h:inputText id="text1" value="#{vowel.str}" required="true" requiredMessage="Field Mustn't Be Empty" tabindex="5" maxlength="15"/></td> <td><h:message for="text1" style="color:red" /></td> </tr> <tr> <td>New String In Lower Case : </td> <td><h:outputText value="#{vowel.strLower}"/></td> </tr> <tr> <td><h:commandButton value="Get Lower" action="#{vowel.lower(vowel.str)}" /></td> </tr> </table> </h:form> </h:body> </html>
Continue...
delete.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>Delete Character Example</title> </h:head> <h:body> <h1>JSF Example</h1> <h:form id="form1"> <table> <tr> <td>Enter A String : </td> <td><h:inputText id="text2" value="#{vowel.str}" required="true" requiredMessage="Field Mustn't Be Empty" tabindex="5" maxlength="15"/></td> <td><h:message for="text2" style="color:red" /></td> </tr> <tr> <td>Enter Character To Delete : </td> <td><h:inputText id="text1" value="#{vowel.ch1}" required="true" requiredMessage="Field Mustn't Be Empty" tabindex="5" maxlength="15" accesskey="c"/></td> <td><h:message for="text1" style="color:red" /></td> </tr> <tr> <td>New String After Delete</td> <td><h:outputText value="#{vowel.str1}"/></td> </tr> <tr> <td><h:commandButton value="Delete Character" action="#{vowel.deleteChar(vowel.ch1)}" /></td> </tr> </table> </h:form> </h:body> </html>
Continue...
FindVowel.java
package devmanuals; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; @ManagedBean(name="vowel") @RequestScoped public class FindVowel { String str, str1, revString="", strUpper="", strLower=""; int count=0; char ch; char ch1, ch2; public String getStrLower() { return strLower; } public String getStrUpper() { return strUpper; } public String getRevString() { return revString; } public String getStr() { return str; } public void setStr(String str) { this.str = str; } public int getCount() { return count; } public String getStr1() { return str1; } public char getCh1() { return ch1; } public void setCh1(char ch1) { this.ch1 = ch1; } public void lower(String str2) { //String newString=""; StringBuffer sb = new StringBuffer(); for(int i=0; i < str2.length(); i++) { //System.out.println(i+" "+str2.charAt(i)); //str2.charAt(i); if(i < 2) { sb.append(str2.charAt(i)); } if(i==2) { char c = str2.charAt(i); String u = Character.toString(c); sb.append(u.toLowerCase()); } if(i > 2) { sb.append(str2.charAt(i)); } } strLower = sb.toString(); } public void upper(String str2) { //String newString=""; StringBuffer sb = new StringBuffer(); for(int i=0; i < str2.length(); i++) { //System.out.println(i+" "+str2.charAt(i)); //str2.charAt(i); if(i < 1) { sb.append(str2.charAt(i)); } if(i==1) { char c = str2.charAt(i); String u = Character.toString(c); sb.append(u.toUpperCase()); } if(i > 1) { sb.append(str2.charAt(i)); } } strUpper = sb.toString(); } public void reverseString(String str2) { for(int i=str2.length()-1; i >= 0; i--) { revString = revString+str2.charAt(i); } } public void deleteChar(char c) { if(c != 0) { for(int i=0; i< str.length(); i++) { ch2 = str.charAt(i); if(c == ch2) { str1 = str.replace(""+c, ""); } } } } public void getVowel(String text) { if(text != null) { for(int i = 0; i< text.length(); i++) { ch = text.charAt(i); if(ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U') { count++; } } } } }
Thanks.
Ads