Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. <?php
  2.  
  3. class Article
  4. {
  5. private $title;
  6. private $content;
  7. private $author;
  8.  
  9. /**
  10. * Article constructor.
  11. * @param $title
  12. * @param $content
  13. * @param $author
  14. */
  15. public function __construct($title, $content, $author)
  16. {
  17. $this->setTitle($title);
  18. $this->setContent($content);
  19. $this->setAuthor($author);
  20. }
  21.  
  22.  
  23. /**
  24. * @return mixed
  25. */
  26. public function getTitle()
  27. {
  28. return $this->title;
  29. }
  30.  
  31. /**
  32. * @param mixed $title
  33. */
  34. public function setTitle($title): void
  35. {
  36. $this->title = $title;
  37. }
  38.  
  39. /**
  40. * @return mixed
  41. */
  42. public function getContent()
  43. {
  44. return $this->content;
  45. }
  46.  
  47. /**
  48. * @param mixed $content
  49. */
  50. public function setContent($content): void
  51. {
  52. $this->content = $content;
  53. }
  54.  
  55. /**
  56. * @return mixed
  57. */
  58. public function getAuthor()
  59. {
  60. return $this->author;
  61. }
  62.  
  63. /**
  64. * @param mixed $author
  65. */
  66. public function setAuthor($author): void
  67. {
  68. $this->author = $author;
  69. }
  70.  
  71. public function __toString()
  72. {
  73. return $this->getTitle() . ' - ' . $this->getContent() . ': ' . $this->getAuthor() . PHP_EOL;
  74. }
  75.  
  76. }
  77. $articles = [];
  78. $input = readline();
  79. $tokens = explode(', ', $input);
  80. $title = $tokens[0];
  81. $content = $tokens[1];
  82. $author = $tokens[2];
  83.  
  84. $article = new Article($title, $content, $author);
  85. $commandCount = intval(readline());
  86.  
  87. for ($i = 0; $i < $commandCount; $i++) {
  88. $input = readline();
  89. $tokens = explode(': ', $input);
  90. $command = $tokens[0];
  91. $data = $tokens[1];
  92. if ($command === 'Edit') {
  93. $article->setContent($data);
  94. } else if ($command === 'ChangeAuthor') {
  95. $article->setAuthor($data);
  96. } else if ($command === 'Rename') {
  97. $article->setTitle($data);
  98. } else {
  99. continue;
  100. }
  101. }
  102. echo $article;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement