Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Movie
- {
- private $title;
- private $studio;
- private $rating;
- public function __construct(string $title, string $studio, string $rating)
- {
- $this->title = $title;
- $this->studio = $studio;
- $this->rating = $rating;
- }
- public function getTitle(): string
- {
- return $this->title;
- }
- public function getStudio(): string
- {
- return $this->studio;
- }
- public function getRating(): string
- {
- return $this->rating;
- }
- }
- class MoviesManager
- {
- private $movies;
- public function __construct(array $movies)
- {
- $this->movies = $movies;
- }
- public function getTitles(): array
- {
- $titles = [];
- foreach ($this->movies as $movie)
- {
- $titles[] = $movie->getTitle();
- }
- return $titles;
- }
- public function getPG(): array
- {
- $pgs = [];
- foreach ($this->movies as $movie)
- {
- $pgs[] = $movie->getRating();
- }
- return $pgs;
- }
- public function getPG13()
- {
- $pgs = [];
- foreach ($this->movies as $movie)
- {
- if ($movie->getRating() === 'PG13')
- {
- $pgs[] = $movie->getTitle();
- }
- }
- return $pgs;
- }
- }
- $movies = [
- new Movie('Casino Royale', 'Eon Productions', 'PG13'),
- new Movie('Glass', 'Buena Vista International', 'PG13'),
- new Movie('Spider-Man: Into the Spider-Verse', 'Columbia Pictures', 'PG'),
- ];
- $moviesManager = new MoviesManager($movies);
- echo implode('|', $moviesManager->getPG13());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement