Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. <?php
  2.  
  3. class Movie
  4. {
  5. private $title;
  6. private $studio;
  7. private $rating;
  8.  
  9. public function __construct(string $title, string $studio, string $rating)
  10. {
  11. $this->title = $title;
  12. $this->studio = $studio;
  13. $this->rating = $rating;
  14. }
  15.  
  16. public function getTitle(): string
  17. {
  18. return $this->title;
  19. }
  20.  
  21. public function getStudio(): string
  22. {
  23. return $this->studio;
  24. }
  25.  
  26. public function getRating(): string
  27. {
  28. return $this->rating;
  29. }
  30. }
  31.  
  32. class MoviesManager
  33. {
  34. private $movies;
  35.  
  36. public function __construct(array $movies)
  37. {
  38. $this->movies = $movies;
  39. }
  40.  
  41. public function getTitles(): array
  42. {
  43. $titles = [];
  44.  
  45. foreach ($this->movies as $movie)
  46. {
  47. $titles[] = $movie->getTitle();
  48. }
  49.  
  50. return $titles;
  51. }
  52.  
  53. public function getPG(): array
  54. {
  55. $pgs = [];
  56.  
  57. foreach ($this->movies as $movie)
  58. {
  59. $pgs[] = $movie->getRating();
  60. }
  61.  
  62. return $pgs;
  63. }
  64.  
  65. public function getPG13()
  66. {
  67. $pgs = [];
  68.  
  69. foreach ($this->movies as $movie)
  70. {
  71. if ($movie->getRating() === 'PG13')
  72. {
  73. $pgs[] = $movie->getTitle();
  74. }
  75. }
  76.  
  77. return $pgs;
  78. }
  79. }
  80.  
  81. $movies = [
  82. new Movie('Casino Royale', 'Eon Productions', 'PG13'),
  83. new Movie('Glass', 'Buena Vista International', 'PG13'),
  84. new Movie('Spider-Man: Into the Spider-Verse', 'Columbia Pictures', 'PG'),
  85. ];
  86.  
  87. $moviesManager = new MoviesManager($movies);
  88.  
  89. echo implode('|', $moviesManager->getPG13());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement