Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. package ObjectNClasses.Articles;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. String[] input = scanner.nextLine().split(", ");
  9. String title = input[0];
  10. String content = input[1];
  11. String author = input[2];
  12. Article article = new Article(title, content, author);
  13. int n = Integer.parseInt(scanner.nextLine());
  14. for (int i = 0; i < n; i++) {
  15. input = scanner.nextLine().split(": ");
  16. String command = input[0];
  17. switch (command) {
  18. case "Edit":
  19. article.edit(input[1]);
  20. break;
  21. case "ChangeAuthor":
  22. article.changeAuthor(input[1]);
  23. break;
  24. case "Rename":
  25. article.rename(input[1]);
  26. break;
  27. }
  28. }
  29. System.out.println(article);
  30. }
  31. public static class Article {
  32. private String title;
  33. private String content;
  34. private String author;
  35.  
  36. public Article(String title, String content, String author) {
  37. this.title = title;
  38. this.content = content;
  39. this.author = author;
  40. }
  41.  
  42. public void edit(String content) {
  43. this.content = content;
  44. //Заменяме старият с новият.
  45. }
  46.  
  47. public void changeAuthor(String author) {
  48. this.author = author;
  49. }
  50.  
  51. public void rename(String title) {
  52. this.title = title;
  53. }
  54.  
  55. @Override
  56. public String toString() {
  57. String result = String.format("%s - %s: %s",
  58. this.title, this.content, this.author);
  59. return result;
  60. }
  61.  
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement