Advertisement
Guest User

2.8.6 Speaking

a guest
Sep 17th, 2019
1,057
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public class Talker
  2. {
  3. private String text;
  4.  
  5. // Constructor
  6. public Talker(String startingText)
  7. {
  8. text = startingText;
  9. }
  10.  
  11. // Returns the text in all uppercase letters
  12. // Find a method in the JavaDocs that
  13. // will allow you to do this with just
  14. // one method call
  15. public String yell()
  16. {
  17. String sub = text.toUpperCase();
  18.  
  19. return sub;
  20. }
  21.  
  22. // Returns the text in all lowercase letters
  23. // Find a method in the JavaDocs that
  24. // will allow you to do this with just
  25. // one method call
  26. public String whisper()
  27. {
  28. String sub = text.toLowerCase();
  29. return sub;
  30. }
  31.  
  32. // Reset the instance variable to the new text
  33. public void setText(String newText)
  34. {
  35. text = newText;
  36. System.out.println(text);
  37. }
  38.  
  39. // Returns a String representatin of this object
  40. // The returned String should look like
  41. //
  42. // I say, "text"
  43. //
  44. // The quotes should appear in the String
  45. // text should be the value of the instance variable
  46. public String toString()
  47. {
  48. return "I say, \""+text+"\"";
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement