-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibrary.php
45 lines (39 loc) · 1.12 KB
/
Library.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
class Library {
public $id;
public $numberOfBooks;
public $signUpDays;
public $shipAmount;
public $bookIds;
public $scannedBooks = [];
public function __construct($id, $numberOfBooks, $signUpDays, $shipAmount, $bookIds)
{
$this->id = $id;
$this->numberOfBooks = (int) $numberOfBooks;
$this->signUpDays = (int) $signUpDays;
$this->shipAmount = (int) $shipAmount;
$this->bookIds = $bookIds;
}
public function scanBooks($alreadyScannedBooks)
{
for($i=0; $i<$this->shipAmount; $i++) {
if (empty($this->bookIds)) {
break;
}
$book = array_pop($this->bookIds);
while (isset($alreadyScannedBooks[$book])) {
$book = array_pop($this->bookIds);
}
if ($book == null) {
break;
}
$alreadyScannedBooks[$book] = true;
$this->scannedBooks[] = $book;
}
return $alreadyScannedBooks;
}
public function getScannedBooksNumber()
{
return count($this->scannedBooks);
}
}