import java.util.Scanner;
class RealEstate {
public static String generateAdvertisement(String str) {
if (str.length() == 0)
throw new IllegalArgumentException("Please enter a valid phrase");
// split the input string into a list of words
String[] words = str.split(" ");
String newStr = "";
// loop through each word
for (int i = 0;i < words.length;i++) {
String currentWord = words[i];
// loop through each letter - execpt the first - always accept
// the first letter of a word, even if it is a vowel
newStr += currentWord.charAt(0);
for (int k = 1;k < currentWord.length();k++) {
char currentLetter = currentWord.charAt(k);
if (!isVowel(currentLetter))
newStr += currentLetter;
}
newStr += " ";
}
return newStr;
}
public static boolean isVowel(char currentLetter) {
return currentLetter == 'a' ||
currentLetter == 'i' ||
currentLetter == 'o' ||
currentLetter == 'e' ||
currentLetter == 'u';
}
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Input the text you wish to Real Estatify");
System.out.println();
System.out.println("Example: ");
System.out.print("'Desirable unfurnished flat in quiet residential area' is: ");
System.out.println(generateAdvertisement("Desirable unfurnished flat in quiet residential area"));
System.out.println("\n Enter text now: ");
String input = keyboard.nextLine();
String output = generateAdvertisement(input);
System.out.println("Output is: \n" + output);
}
}
|