Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. package Exercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Articles {
  6.  
  7. static class Article {
  8. private String title;
  9. private String content;
  10. private String author;
  11.  
  12. public String getTitle() {
  13. return title;
  14. }
  15.  
  16. public String getContent() {
  17. return content;
  18. }
  19.  
  20. public String getAuthor() {
  21. return author;
  22. }
  23.  
  24. public void setTitle(String title) {
  25. this.title = title;
  26. }
  27.  
  28. public void setContent(String content) {
  29. this.content = content;
  30. }
  31.  
  32. public void setAuthor(String author) {
  33. this.author = author;
  34. }
  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. @Override
  43. public String toString() {
  44. return String.format("%s - %s: %s", title, content, author);
  45. }
  46.  
  47. }
  48.  
  49.  
  50. public static void main(String[] args) {
  51. Scanner scanner = new Scanner(System.in);
  52.  
  53. String[] input = scanner.nextLine().split(", ");
  54.  
  55. String title = input[0];
  56. String content = input[1];
  57. String author = input[2];
  58.  
  59. Article article = new Article(title, content, author);
  60.  
  61. int n = Integer.parseInt(scanner.nextLine());
  62.  
  63. for (int i = 0; i < n; i++) {
  64.  
  65. String[] commandInput = scanner.nextLine().split(":");
  66.  
  67. String command = commandInput[0];
  68. String change = commandInput[1].trim();
  69.  
  70. if (command.equals("Edit")) {
  71. article.setContent(change);
  72.  
  73. } else if (command.equals("ChangeAuthor")) {
  74. article.setAuthor(change);
  75.  
  76. } else if (command.equals("Rename")) {
  77. article.setTitle(change);
  78.  
  79. }
  80.  
  81.  
  82. }
  83.  
  84. System.out.println(article);
  85.  
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement