Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java program question: Write the function String PluralForm(String word) which t

ID: 3723307 • Letter: J

Question

Java program question:

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.

Here are three examples of the output, software is very picky so it has to look exactly like this unfortunately:

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.

Explanation / Answer

import java.util.Scanner;
class Main {
static String makePlural(String singularWord) {
String pluralWord = "";
int length = singularWord.length();
String checker = singularWord.substring(0, singularWord.length() - 1);
char lastLetter = singularWord.charAt(singularWord.length() - 1);

if (length == 1) {
pluralWord = singularWord + "'s";
} else
switch (lastLetter) {
case 's':
case 'x':
case 'z':
pluralWord = singularWord + "es";
break;
case 'h':
if ((singularWord.charAt(singularWord.length() - 2) == 'c') || (singularWord.charAt(singularWord.length() - 2) == 's')) {
pluralWord = singularWord + "es";
break;
}
case 'f':
if (EnglishConsonant(singularWord.charAt(singularWord.length() - 2))) {
pluralWord = checker + "ves";
break;
}
case 'y':
if (EnglishConsonant(singularWord.charAt(singularWord.length() - 2))) {
pluralWord = checker + "ies";
break;
}
default:
pluralWord = singularWord + "s";
break;
}
return pluralWord;
}
public static boolean EnglishConsonant(char ch) {
switch (Character.toLowerCase(ch)) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return false;
default:
return true;
}
}


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter a work to convert in into plural");
String singular=sc.next();
System.out.println("Converted String is");
String plural=makePlural(singular);
System.out.println(plural);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote