Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. class Video
  2. {
  3. private $title;
  4. private $amount;
  5. private $avgRating;
  6.  
  7. public function __construct(string $title, int $amount, float $avgRating)
  8. {
  9. $this->title = $title;
  10. $this->amount = $amount;
  11. $this->avgRating = $avgRating;
  12. }
  13.  
  14. public function listVideo(): string
  15. {
  16. return 'Title: ' . $this->title . ', Amount: ' . $this->amount . ', Rating: ' . $this->avgRating . "\n";
  17. }
  18.  
  19. public function rentOutVideo(string $title)
  20. {
  21. $this->title = $title;
  22.  
  23. }
  24. }
  25.  
  26. class VideoStore
  27. {
  28. private $videos;
  29.  
  30. public function __construct(array $videos)
  31. {
  32.  
  33. $this->videos = $videos;
  34. }
  35.  
  36. public function listAllVideos(): array
  37. {
  38. $allVideos = [];
  39.  
  40. foreach ($this->videos as $video) {
  41. $allVideos[] = $video->listVideo();
  42. }
  43.  
  44. return $allVideos;
  45. }
  46. }
  47. $videos = [
  48. new Video('The Matrix', 11, '6.5'),
  49. new Video('Godfather II', 3, '8.9'),
  50. new Video('Star Wars Episode IV: A New Hope', 1, '9.1')
  51. ];
  52.  
  53. $videostore = new VideoStore($videos);
  54. echo implode('', $videostore->listAllVideos());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement