Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. /**
  2. This class models a simple letter.
  3. */
  4. public class Letter
  5. {
  6. private String from;
  7. private String to;
  8. private String text;
  9.  
  10. /**
  11. Constructs a letter with a given sender and recipient.
  12. @param from the sender
  13. @param to the recipient
  14. */
  15. public Letter(String from, String to)
  16. {
  17. this.from = from;
  18. this.to = to;
  19. text = "";
  20. }
  21.  
  22. /**
  23. Adds a line to the body of this letter.
  24. */
  25. public void addLine(String line)
  26. {
  27. text = text +line + "\n";
  28. }
  29.  
  30. /**
  31. Gets the text of this letter.
  32. */
  33. public String getText()
  34. {
  35. String output = "Dear " + to + ":\n\n";
  36. output += text + "\nSincerely,\n\n" + from + ".";
  37. return output;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement