**Please, JAVA answers only!** Write the function String PluralForm(String word)
ID: 3670443 • Letter: #
Question
**Please, JAVA answers only!**
Write the function String PluralForm(String word) which takes a standard English word as a parameter and returns the plural form based on the following English rules.
Punctuation should be preserved. If the word ends in s, x, z, ch, or sh, add es to the end of the word. If the word ends in o preceded by a consonant, add es to the end of the word. If the word ends in y preceded by a consonant, replace the y with ies. For all other cases, add an s to the end of the word. Each word provided as input will comprise lowercase alphabetic characters.
Also, each word may be terminated by one "normal" punctuation mark (i.e., any from ,.!?;). Input words will not contain any spaces, numeric digits, or other unspecified non-alphabetic characters.
EXAMPLE ***
Explanation / Answer
import java.util.Scanner;
public class StringPlural {
public static void FindPlural(String str)
{
if(str.endsWith("s")||str.endsWith("x")||str.endsWith("z"))
{
System.out.println(str.substring(0, str.length()-1)+"es");
}
else if(str.endsWith("ch")||str.endsWith("sh"))
{
System.out.println(str.substring(0, str.length()-2)+"es");
}
else if(str.endsWith("y")&&((str.charAt(str.length()-1))=='b'||(str.charAt(str.length()-1))=='c'||(str.charAt(str.length()-1))=='d'||(str.charAt(str.length()-1))=='f'||(str.charAt(str.length()-1))=='g'||(str.charAt(str.length()-1))=='h'||(str.charAt(str.length()-1))=='i'||(str.charAt(str.length()-1))=='j'||(str.charAt(str.length()-1))=='k'||(str.charAt(str.length()-1))=='l'||(str.charAt(str.length()-1))=='m'||(str.charAt(str.length()-1))=='n'||(str.charAt(str.length()-1))=='p'||(str.charAt(str.length()-1))=='q'||(str.charAt(str.length()-1))=='r'||(str.charAt(str.length()-1))=='s'||(str.charAt(str.length()-1))=='t'||(str.charAt(str.length()-1))=='v'||(str.charAt(str.length()-1))=='w'||(str.charAt(str.length()-1))=='z'||(str.charAt(str.length()-1))=='x'))
{
System.out.println(str.substring(0, str.length()-1)+"ies");
}
else
{
System.out.println(str.substring(0, str.length())+"s");
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str= sc.next();
FindPlural(str);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.