Course: Eecs1022 Pe2: Add Wechat For More Information Contact Us
Course: Eecs1022 Pe2: Add Wechat For More Information Contact Us
Tutor:John
Email: [email protected]
往期知识点回顾
String.format
Format
Example
1 2D array
两个指针在游动
应用 : Matrix
Example Input and Output: Enter the number of rows: 3 Enter the number of
columns: 4 The 2D array is: 2 6 8 4 9 7 1 5 10 3 2 8 The sum of elements in
row 0 is: 20 The sum of elements in row 1 is: 22 The sum of elements in row 2
is: 23
2 OOP
1 分析题目
2 理解需求
创造 method 与 attribute
Constructor
4 Coding
6 Debug
1. Book class: a class that represents a book. It should have the following
attributes: title, author, publication year, and whether the book is
available or checked out.
2. User class: a class that represents a library user. It should have the
following attributes: name and a list of books that the user has
borrowed.
3. Library class: a class that represents a library. It should have the
following attributes: a list of books in the library, and a list of
users who have registered with the library.
4. The Book class should have the following methods:
o checkOut(): A method that sets the book to checked out
o checkIn(): A method that sets the book to available
o isAvailable(): A method that returns true if the book is
available, false otherwise
o toString(): A method that returns a formatted string
representation of the book's properties
5. The User class should have the following methods:
o borrowBook(): A method that adds a borrowed book to the list of
borrowed books
o returnBook(): A method that removes a returned book from the list
of borrowed books
6. The Library class should have the following methods:
o addBook(): A method that adds a book to the library
o removeBook(): A method that removes a book from the library
o registerUser(): A method that adds a user to the list of library
users
o deregisterUser(): A method that removes a user from the list of
library users
Write a main function that creates a Library instance, adds some books to the
library, registers some users, and then simulates user activity by having some
users borrow and return books. Ensure that the state of books and users is
updated properly at all times.
Note:
• You can implement any additional methods you think necessary to make
this program complete.
本章总结