fork download
  1. <?php
  2.  
  3. /*
  4. * README
  5. * ======
  6. *
  7. * This is simple source code for bookstore application.
  8. * The functional requirement that you needed to help you understand the user story has been written.
  9. *
  10. * Your mission is :
  11. *
  12. * 1. Complete these source code at "PLACE YOUR CODE HERE" parts and run them without any error.
  13. * 2. The result has to be:
  14. * 1:true
  15. * 2:true
  16. * 3:true
  17. * 4:true
  18. * 5:true
  19. * 3. Send the source code file with your answers.
  20. */
  21.  
  22. // PHP v5.4
  23. $app = new TestApplication;
  24. $app->run();
  25.  
  26. class TestApplication {
  27. public function run() {
  28. $shop = new Shop;
  29. $books = array(
  30. new Book('The Fellowship of the Ring', 'J.R.R. Tolkien'),
  31. new Book('The Two Towers', 'J.R.R. Tolkien'),
  32. new Book('The Return of the King', 'J.R.R. Tolkien'),
  33. new Book('The Hobbit', 'J.R.R. Tolkien'),
  34. new Book('Harry Potter and the Sorcerer\'s Stone', 'J.K. Rowling'),
  35. new Book('Harry Potter and the Chamber of Secrets', 'J.K. Rowling'),
  36. new Book('Harry Potter and the Prisoner of Azkaban', 'J.K. Rowling'),
  37. new Book('Harry Potter and the Goblet of Fire', 'J.K. Rowling'),
  38. new Book('Harry Potter and the Order of the Phoenix', 'J.K. Rowling'),
  39. new Book('Harry Potter and the Half-Blood Prince', 'J.K. Rowling'),
  40. new Book('Harry Potter and the Deathly Hallows', 'J.K. Rowling'),
  41. );
  42. foreach ($books as $book) {
  43. $shop->bookAdd($book);
  44. }
  45. $ahmad = new Person('Ahmad Ramadhan');
  46. $available = $shop->bookIsAvailable('The Two Towers');
  47. if ($available) {
  48.  
  49. $book = $shop->bookGet('The Two Towers');
  50. $ahmad->addToBag($book);
  51. echo "1: true";
  52. } else {
  53.  
  54. echo "1: false";
  55. }
  56. echo "\n";
  57. }
  58. }
  59.  
  60.  
  61. class Shop {
  62. public $listBook = [];
  63. private $find_book;
  64.  
  65. function bookAdd($books){
  66. $books = (array) $books;
  67. $this->listBook = array_push($this->listBook, $books );
  68. }
  69.  
  70. function bookIsAvailable($names_book){
  71. echo $names_book;
  72. echo "/n";
  73. var_dump($this->listBook);
  74. $this->find_book= array_search($names_book, $this->listBook);
  75. if($this->find_book){
  76. return true;
  77. }else{
  78. return false;
  79. }
  80. }
  81.  
  82. function bookListByAuthor($author){
  83.  
  84. }
  85.  
  86. function bookGet($name_book){
  87.  
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94. }
  95.  
  96.  
  97. class Book {
  98. public $title_book;
  99. public $author;
  100. public function __construct($title_book, $author){
  101. $this->title_book = $title_book;
  102. $this->author = $author;
  103. }
  104.  
  105. }
  106.  
  107. class Person
  108. {
  109. public $firstname;
  110. private $book=[];
  111.  
  112. public function __construct($firstname){
  113. $this->firstname = $firstname;
  114. }
  115.  
  116. function addToBag($books){
  117. array_push($this->book, $books);
  118. }
  119.  
  120. }
Success #stdin #stdout #stderr 0.02s 26172KB
stdin
Standard input is empty
stdout
The Two Towers/nNULL
1: false
stderr
PHP Warning:  array_push() expects parameter 1 to be array, int given in /home/1QyjZA/prog.php on line 67
PHP Warning:  array_push() expects parameter 1 to be array, null given in /home/1QyjZA/prog.php on line 67
PHP Warning:  array_push() expects parameter 1 to be array, null given in /home/1QyjZA/prog.php on line 67
PHP Warning:  array_push() expects parameter 1 to be array, null given in /home/1QyjZA/prog.php on line 67
PHP Warning:  array_push() expects parameter 1 to be array, null given in /home/1QyjZA/prog.php on line 67
PHP Warning:  array_push() expects parameter 1 to be array, null given in /home/1QyjZA/prog.php on line 67
PHP Warning:  array_push() expects parameter 1 to be array, null given in /home/1QyjZA/prog.php on line 67
PHP Warning:  array_push() expects parameter 1 to be array, null given in /home/1QyjZA/prog.php on line 67
PHP Warning:  array_push() expects parameter 1 to be array, null given in /home/1QyjZA/prog.php on line 67
PHP Warning:  array_push() expects parameter 1 to be array, null given in /home/1QyjZA/prog.php on line 67
PHP Warning:  array_search() expects parameter 2 to be array, null given in /home/1QyjZA/prog.php on line 74