Page 388 - Computer_Science_F5
P. 388
Stage Three: Implementing the project
1. Coding
Book Class: Chapter Five: Object oriented programming with Java
class Book:
FOR ONLINE READING ONLY
def __init__(self, title, author, isbn, available_copies):
self.title = title
self.author = author
self.isbn = isbn
self.available_copies = available_copies
def checkout(self):
if self.available_copies > 0:
self.available_copies -= 1
return True
return False
def return_book(self):
self.available_copies += 1
User Class:
class User:
def __init__(self, name, user_id):
self.name = name
self.user_id = user_id
self.checked_out_books = []
def checkout_book(self, book):
if book.checkout():
self.checked_out_books.append(book)
print(f”{book.title} checked out successfully.”)
else:
print(f”{book.title} is not available.”)
def return_book(self, book):
if book in self.checked_out_books:
book.return_book()
379
Student’s Book Form Five
Computer Science Form 5.indd 379 23/07/2024 12:34

