Advertisement
desislava_topuzakova

Single Responsibility Example

Jul 10th, 2023
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. package solid.singleRespExamples;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class TextManipulator {
  6. private String text;
  7.  
  8. public TextManipulator(String text) {
  9. this.text = text;
  10. }
  11.  
  12. public String getText() {
  13. return text;
  14. }
  15.  
  16. public void appendText(String newText) {
  17. text = text.concat(newText);
  18. }
  19.  
  20. public String findWordAndReplace(String word, String replacementWord) {
  21. if (text.contains(word)) {
  22. text = text.replace(word, replacementWord);
  23. }
  24. return text;
  25. }
  26.  
  27. public String findWordAndDelete(String word) {
  28. if (text.contains(word)) {
  29. text = text.replace(word, "");
  30. }
  31. return text;
  32. }
  33.  
  34. public void printText() {
  35. System.out.println(text);
  36. }
  37.  
  38. public void printOutEachWordOfText() {
  39.  
  40. System.out.println(Arrays.toString(text.split(" ")));
  41. }
  42.  
  43. public void printRangeOfCharacters(int startingIndex, int endIndex) {
  44.  
  45. System.out.println(text.substring(startingIndex, endIndex));
  46. }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement