Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Articles_ {
  4. static class Article{
  5. public void setTitle(String title) {
  6. this.title = title;
  7. }
  8.  
  9. public void setContent(String content) {
  10. this.content = content;
  11. }
  12.  
  13. public void setAuthor(String author) {
  14. this.author = author;
  15. }
  16.  
  17. public String getTitle() {
  18. return title;
  19. }
  20.  
  21. public String getContent() {
  22. return content;
  23. }
  24.  
  25. public String getAuthor() {
  26. return author;
  27. }
  28.  
  29. String title;
  30. String content;
  31. String author;
  32.  
  33.  
  34. public Article(String title, String content, String author) {
  35. this.title = title;
  36. this.content = content;
  37. this.author = author;
  38. }
  39.  
  40. public void edit(String newContent){
  41. setContent(newContent);
  42.  
  43.  
  44.  
  45.  
  46. }
  47. public void changeAuthor(String newAuthor){
  48. setAuthor(newAuthor);
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55. public void Rename(String newtitle){
  56. setTitle(newtitle);
  57.  
  58.  
  59.  
  60.  
  61. }
  62. public String toString(String output){
  63. output=getTitle()+" -"+getContent()+":"+getAuthor();
  64. return output;
  65.  
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72. }
  73. public static void main(String[] args) {
  74. Scanner scanner=new Scanner(System.in);
  75. String line=scanner.nextLine();
  76. String[] array=line.split(",");
  77. String title=array[0];
  78. String content=array[1];
  79. String author=array[2];
  80. int n=Integer.parseInt(scanner.nextLine());
  81. Article article=new Article(title,content,author);
  82. for (int i = 0; i <n ; i++) {
  83.  
  84. String secondline = scanner.nextLine();
  85. String[] secondarray = secondline.split(":");
  86.  
  87.  
  88. if (secondarray[0].equals("Edit")) {
  89. article.edit(secondarray[1]);
  90.  
  91. }
  92.  
  93. else if (secondarray[0].equals("ChangeAuthor")) {
  94.  
  95. article.changeAuthor(secondarray[1]);
  96.  
  97. }
  98.  
  99. else if (secondarray[0].equals("Rename")) {
  100. article.Rename(secondarray[1]);
  101.  
  102. }
  103.  
  104.  
  105.  
  106.  
  107. }
  108.  
  109. String output="";
  110. output=article.toString(output);
  111.  
  112. System.out.println(output);
  113.  
  114.  
  115.  
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement