Advertisement
Guest User

6C

a guest
Oct 17th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. /**
  2. * Provides some methods to manipulate text
  3. *
  4. * @author Tirth Patel
  5. */
  6. public class LoopyText
  7. {
  8. private String text;
  9.  
  10. /**
  11. * Creates a LoopyText object with the given text
  12. * @param theText the text for this LoopyText
  13. */
  14. public LoopyText(String theText)
  15. {
  16. text = theText;
  17. }
  18.  
  19. /**
  20. * Gets every second character of the string
  21. * @return the second character
  22. */
  23. public String getEverySecondCharacter()
  24. {
  25. String secondChar="";
  26. for(int i=0; i<text.length()/2; i++)
  27. {
  28. secondChar = secondChar + text.charAt(i*2+1);
  29. }
  30. return secondChar;
  31. }
  32.  
  33. /**
  34. * Gets the number of uppercase letters in the text
  35. * @return the number of uppercase letters
  36. */
  37. public int upperCaseCount()
  38. {
  39. int caseCount=0;
  40. for (int i=0; i<text.length(); i++)
  41. {
  42. if(Character.isUpperCase(text.charAt(i)))
  43. {
  44. caseCount++;
  45. }
  46. }
  47. return caseCount;
  48. }
  49.  
  50. /**
  51. * Returns a string consisting of the first character of each word
  52. * @return the first character
  53. */
  54. public String firstLetters()
  55. {
  56. String firstChar = "";
  57. for (String space : text.split(" "))
  58. {
  59. firstChar = firstChar + space.charAt(0);
  60. }
  61. return firstChar;
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement