Advertisement
Tgynac

Untitled

Nov 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /**
  2. * SkillBuilder5 is a class for completing the Skill
  3. * Builder 5 assignment in Java.
  4. *
  5. * @author <You>
  6. * @version 1.0
  7. */
  8.  
  9. public class SkillBuilder5
  10. {
  11. // define your constants after this comment
  12. private final static int No_t = 0;
  13. private final static int One_t = 1;
  14. private final static int Yes_t_y = 2;
  15. // define your constants before this comment
  16.  
  17. public static String findTYPattern(String s)
  18. {
  19. // add your code here.
  20. String str = "Hello, my name is Tom Brady and I am thirsty";
  21. boolean isDone = false;
  22. int index = 0;
  23. int currentState = 0;
  24.  
  25. while((index < s.length()) && (!(isDone))){
  26. char ch = s.charAt(index);
  27. index++;
  28. switch(currentState)
  29. {
  30. case(No_t):
  31. if(Character.toLowerCase(ch) == 't')
  32. {
  33. str = str + ch;
  34. currentState = One_t;
  35. }break;
  36. case(One_t):
  37. if(Character.toLowerCase(ch) == 'y')
  38. {
  39. currentState = Yes_t_y;
  40. }
  41. str = str+ch;
  42. break;
  43. case(Yes_t_y):
  44. isDone = true;
  45. break;
  46. }
  47. }
  48. return str;}
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement