import java.io.*;
import java.util.StringTokenizer;
import java.util.HashSet;
public class Vowels{
private static FileInputStream inputFile;
private static InputStreamReader inputReader;
private static BufferedReader lineReader;
private static StringTokenizer tokenizer;
public static void main(String args[]) throws IOException
{
//Methods
importFile();
sortInfo();
}
public static void importFile() throws IOException
{
//Data Input
inputFile = new FileInputStream ("D:\\My Documents\\Senior\\APCompsci\\VHS APCS\\Data\\blooby.txt");
inputReader = new InputStreamReader (inputFile);
lineReader = new BufferedReader (inputReader);
}
public static void sortInfo() throws IOException
{
//Line can't be null to begin.
String line = new String("start");
while (line != null){
line = lineReader.readLine();
//Stops process when there is no more information in the input file.
if (line == null){
break;
}
tokenizer = new StringTokenizer(line, " ");
String stem = tokenizer.nextToken();
String suffix = tokenizer.nextToken();
//Test
System.out.println("Original String: "+ stem +" "+ suffix);
//Hashset for comparing
HashSet vowelSet = new HashSet();
vowelSet.add("A");
vowelSet.add("C");
vowelSet.add("S");
vowelSet.add("L");
//Determining endings!
//Check for vowels at end of string (specifically last two characters)
if ((vowelSet.contains(stem.substring(2,3)) == true) && (vowelSet.contains(stem.substring(3,4)) == true)) {
//If last letter is vowel...
if (vowelSet.contains(stem.substring(3, 4)) == true){
//Checking if second to last letter is vowel.
if (vowelSet.contains(stem.substring(2, 3)) == true){
//'STEM ENDS IN DOUBLE VOWEL'
//Add Suffix - Starts with Consonant;
/*Drop the leftmost letter of the final sequence of vowels, then add the suffix*/
if (vowelSet.contains(suffix.substring(0,1)) == false){
StringBuffer buf = new StringBuffer(stem);
buf.replace(2, 3, "");
String stemFinal = buf.toString();
String finalstr = new String (stemFinal + suffix);
System.out.println("w/ Suffix: "+finalstr);
}
//Add Suffix - Starts with Vowel;
/*Add the first letter of the suffix, then add the suffix*/
if (vowelSet.contains(suffix.substring(0,1)) == true){
StringBuffer buf = new StringBuffer(suffix);
char suffixLetter = suffix.charAt(0);
buf.insert(1, suffixLetter);
String suffixFinal = buf.toString();
String finalstr = new String (stem+suffixFinal);
System.out.println("w/ Suffix: "+finalstr);
}
//Add Plural - Double last letter, add 'H'.
StringBuffer buf = new StringBuffer(stem);
char stemLetter = stem.charAt(3);
buf.insert(4, stemLetter);
String finalL = buf.toString();
System.out.println("w/ Plural: "+ finalL + "H");
//But, if not, ends in single vowel.
}else if (vowelSet.contains(stem.substring(2, 3)) == false){
//INSERT CODE FOR 'STEM ENDS IN SINGLE VOWEL'
//Add Suffix - Starts with Consonant;
//Add the first letter of the suffix and then add the suffix.
if (vowelSet.contains(suffix.substring(0,1)) == false){
StringBuffer buf = new StringBuffer(suffix);
char suffixLetter = suffix.charAt(0);
buf.insert(0, suffixLetter);
String suffixFinal = buf.toString();
String finalstr = new String (stem + suffixFinal);
System.out.println("w/ Suffix: "+finalstr);
}
//Add Suffix - Starts with Vowel;
//Drop the first letter of the suffix and add the rest of the suffix
if (vowelSet.contains(suffix.substring(0,1)) == true){
StringBuffer buf = new StringBuffer(suffix);
buf.deleteCharAt(0);
System.out.println(buf);
String suffixFinal = buf.toString();
System.out.println("w/ Suffix: "+stem+suffixFinal);
}
//Plural
//Drop the final vowel and add ‘G’
StringBuffer buf = new StringBuffer(stem);
buf.deleteCharAt(3);
String finalP = buf.toString();
System.out.println("w/ Plural: "+ finalP + "G");
}
//If last letter is not vowel...
}else if (vowelSet.contains(stem.substring(3, 4)) == false){
//INSERT CODE FOR 'ENDS IN SINGLE CONSONANT'
//Add Suffix - Starts with Consonant/Vowel (doesn't matter)
//Simply add the suffix.
System.out.println("w/ Suffix: "+ stem + suffix);
//Plural
//Add “GH”
System.out.println("w/ Plural: "+ stem +"GH");
}
//No vowels. Must be double consonants.
}else if ((vowelSet.contains(stem.substring(2,3)) == false) && (vowelSet.contains(stem.substring(3,4)) == false)){
//INSERT CODE FOR 'STEM ENDS IN DOUBLE CONSONANT' - - - SAME AS DOUBLE VOWEL
//'STEM ENDS IN DOUBLE VOWEL'
//'STEM ENDS IN DOUBLE VOWEL'
//Add Suffix - Starts with Consonant;
/*Drop the leftmost letter of the final sequence of vowels, then add the suffix*/
if (vowelSet.contains(suffix.substring(0,1)) == false){
StringBuffer buf = new StringBuffer(stem);
buf.replace(2, 3, "");
String stemFinal = buf.toString();
String finalstr = new String (stemFinal + suffix);
System.out.println("w/ Suffix: "+finalstr);
}
//Add Suffix - Starts with Vowel;
/*Add the first letter of the suffix, then add the suffix*/
if (vowelSet.contains(suffix.substring(0,1)) == true){
StringBuffer buf = new StringBuffer(suffix);
char suffixLetter = suffix.charAt(0);
buf.insert(1, suffixLetter);
String suffixFinal = buf.toString();
String finalstr = new String (stem+suffixFinal);
System.out.println("w/ Suffix: "+finalstr);
}
//Add Plural - Double last letter, add 'H'.
StringBuffer buf = new StringBuffer(stem);
char stemLetter = stem.charAt(3);
buf.insert(4, stemLetter);
String finalL = buf.toString();
System.out.println("w/ Plural: "+ finalL + "H");
}
}
}
}