Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Video
- {
- private $title;
- private $amount;
- private $avgRating;
- public function __construct(string $title, int $amount, float $avgRating)
- {
- $this->title = $title;
- $this->amount = $amount;
- $this->avgRating = $avgRating;
- }
- public function listVideo(): string
- {
- return 'Title: ' . $this->title . ', Amount: ' . $this->amount . ', Rating: ' . $this->avgRating . "\n";
- }
- public function rentOutVideo(string $title)
- {
- $this->title = $title;
- }
- }
- class VideoStore
- {
- private $videos;
- public function __construct(array $videos)
- {
- $this->videos = $videos;
- }
- public function listAllVideos(): array
- {
- $allVideos = [];
- foreach ($this->videos as $video) {
- $allVideos[] = $video->listVideo();
- }
- return $allVideos;
- }
- }
- $videos = [
- new Video('The Matrix', 11, '6.5'),
- new Video('Godfather II', 3, '8.9'),
- new Video('Star Wars Episode IV: A New Hope', 1, '9.1')
- ];
- $videostore = new VideoStore($videos);
- echo implode('', $videostore->listAllVideos());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement