-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
49 lines (44 loc) · 1.36 KB
/
index.php
File metadata and controls
49 lines (44 loc) · 1.36 KB
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
46
47
48
49
<?php
class Book {
public $title;
public $author;
public $yearPublished;
private $isCheckedOut;
public function __construct($title, $author, $yearPublished) {
$this->title = $title;
$this->author = $author;
$this->yearPublished = $yearPublished;
$this->isCheckedOut = false;
}
public function displayInfo() {
echo "Title: " . $this->title . "<br>";
echo "Author: " . $this->author . "<br>";
echo "Year Published: " . $this->yearPublished . "<br>";
}
public function checkOut() {
if (!$this->isCheckedOut) {
$this->isCheckedOut = true;
echo $this->title . " has been checked out.<br>";
} else {
echo $this->title . " is already checked out.<br>";
}
}
public function returnBook() {
if ($this->isCheckedOut) {
$this->isCheckedOut = false;
echo $this->title . " has been returned.<br>";
} else {
echo $this->title . " was not checked out.<br>";
}
}
}
$book1 = new Book("1984", "George Orwell", 1949);
$book2 = new Book("To Kill a Mockingbird", "Harper Lee", 1960);
echo "<strong>Book 1:</strong><br>";
$book1->displayInfo();
$book1->checkOut(); /
$book1->returnBook();
echo "<br><strong>Book 2:</strong><br>";
$book2->displayInfo();
$book2->checkOut();
?>