Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. private static String separate(String x) //separates the string into separate words
  2. {
  3. if (x.length() == 0){
  4. return "";
  5. }else{
  6. //return pigLatin(x.substring(0, x.indexOf(" "))) + " " + separate(x.substring(x.indexOf(" ") + 1, x.length()));
  7. return separate(x.substring(0, x.indexOf(' ')));
  8. }
  9. }
  10.  
  11. /**
  12. * Receives a String, converts the String to Pig Latin,
  13. * and returns the new Pig Latinated word.
  14. */
  15. public static String pigLatin(String x) //translates the string into piglatin
  16. {
  17. if (x.indexOf('a') == -1 && x.indexOf('e') == -1 && x.indexOf('i') == -1 && x.indexOf('o') == -1 && x.indexOf('u') == -1
  18. && x.indexOf('A') == -1 && x.indexOf('E') == -1 && x.indexOf('I') == -1 && x.indexOf('O') == -1 && x.indexOf('U') == -1){
  19. return x + "ay";
  20. }else if(x.charAt(0) == 'a' || x.charAt(0) == 'e' || x.charAt(0) == 'i' || x.charAt(0) == 'o' || x.charAt(0) == 'u'
  21. || x.charAt(0) == 'A' || x.charAt(0) == 'E' || x.charAt(0) == 'I' || x.charAt(0) == 'O' || x.charAt(0) == 'U'){
  22. return x + "yay";
  23. }else{
  24. return end(x) + start(x) + "ay";
  25. }
  26. }
  27.  
  28. private static String end(String x) //the end part of the piglatin translation
  29. {
  30. if (x.charAt(0) == 'a' || x.charAt(0) == 'e' || x.charAt(0) == 'i' ||
  31. x.charAt(0) == 'o' || x.charAt(0) == 'u'){
  32. return x;
  33. }else{
  34. return end(x.substring(1));
  35. }
  36. }
  37.  
  38. private static String start(String x) //the start part of the piglatin translation
  39. {
  40. int n = 100;
  41. if (x.indexOf('a') != -1 && x.indexOf('a') < n){
  42. n = x.indexOf('a');
  43. }
  44. if (x.indexOf('e') != -1 && x.indexOf('e') < n){
  45. n = x.indexOf('e');
  46. }
  47. if (x.indexOf('i') != -1 && x.indexOf('i') < n){
  48. n = x.indexOf('i');
  49. }
  50. if (x.indexOf('o') != -1 && x.indexOf('o') < n){
  51. n = x.indexOf('o');
  52. }
  53. if (x.indexOf('u') != -1 && x.indexOf('u') < n){
  54. n = x.indexOf('u');
  55. }
  56. if (x.indexOf('A') != -1 && x.indexOf('A') < n){
  57. n = x.indexOf('A');
  58. }
  59. if (x.indexOf('E') != -1 && x.indexOf('E') < n){
  60. n = x.indexOf('E');
  61. }
  62. if (x.indexOf('I') != -1 && x.indexOf('I') < n){
  63. n = x.indexOf('I');
  64. }
  65. if (x.indexOf('O') != -1 && x.indexOf('O') < n){
  66. n = x.indexOf('O');
  67. }
  68. if (x.indexOf('U') != -1 && x.indexOf('U') < n){
  69. n = x.indexOf('U');
  70. }
  71. return x.substring(0,n);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement