package eecs1022.midtermc; /** * The model class of the app. * * @author Franck van Breugel */ public class Translator { private String sentence; /** * Initializes this translator with the given sentence. * * @param sentence a sentence. */ public Translator(String sentence) { this.sentence = sentence; } /** * Returns the translation of the sentence of this translator. * * @return translation of the sentence of this translator. */ public String getTranslation() { final String CONSONANT = "[^aeiou]"; String[] words = this.sentence.split(" "); String translation = ""; for (String word : words) { int i = 0; while (i < word.length() && word.substring(0, i + 1).matches(CONSONANT + "*")) { i++; } word = word.substring(i) + word.substring(0, i); translation = translation + word + "ay "; } return translation.trim(); } }