-->
当前位置:首页 > 题库 > 正文内容

函数题:Implement Library

Luz3年前 (2022-03-01)题库872
我们需要构建代表每个图书馆的类,并管理书籍的集合。所有图书馆都有同样的时间:每天上午9点至下午5点。但是,它们具有不同的地址和图书藏书(即,一系列的图书对象)。

创建一个名为Library的类。复制并粘贴下面的程序框架。在此我们提供了一种创建两个图书馆的主方法,然后对书籍执行一些操作。但是,缺少所有方法和成员变量。你需要定义和实现缺失的方法。

阅读主方法,查看编译错误以找出所丢失的方法。注意有一些方法需要静态方法,而某些则需要是实例方法。比较Strings对象时要小心。使用string1.equals(string2)比较内容string1和string2。

不允许修改main方法。运行此程序时,输出应类似于以下内容:

Library hours:
Libraries are open daily from 9am to 5pm.

Library addresses:
10 Main St.
228 Liberty St.

Borrowing The Lord of the Rings:
You successfully borrowed The Lord of the Rings
Sorry, this book is already borrowed.
Sorry, this book is not in our catalog.

Books available in the first library:
The Da Vinci Code
Le Petit Prince
A Tale of Two Cities

Books available in the second library:
No book in catalog

Returning The Lord of the Rings:
You successfully returned The Lord of the Rings

Books available in the first library:
The Da Vinci Code
Le Petit Prince
A Tale of Two Cities
The Lord of the Rings


### Library类的设计:

根据给出的裁判测试程序,设计完整的Library类。
class Library {
// Add the missing implementation to this class

}



### 裁判测试程序样例:

public class Main {
public static void main(String[] args) {
// Create two libraries
Library firstLibrary = new Library("10 Main St.");
Library secondLibrary = new Library("228 Liberty St.");

// Add four books to the first library
firstLibrary.addBook(new Book("The Da Vinci Code"));
firstLibrary.addBook(new Book("Le Petit Prince"));
firstLibrary.addBook(new Book("A Tale of Two Cities"));
firstLibrary.addBook(new Book("The Lord of the Rings"));

// Print opening hours and the addresses
System.out.println("Library hours:");
Library.printOpeningHours();
System.out.println();

System.out.println("Library addresses:");
firstLibrary.printAddress();
secondLibrary.printAddress();
System.out.println();

// Try to borrow The Lords of the Rings from both libraries
System.out.println("Borrowing The Lord of the Rings:");
firstLibrary.borrowBook("The Lord of the Rings");
firstLibrary.borrowBook("The Lord of the Rings");
secondLibrary.borrowBook("The Lord of the Rings");
System.out.println();

// Print the titles of all available books from both libraries
System.out.println("Books available in the first library:");
firstLibrary.printAvailableBooks();
System.out.println();
System.out.println("Books available in the second library:");
secondLibrary.printAvailableBooks();
System.out.println();

// Return The Lords of the Rings to the first library
System.out.println("Returning The Lord of the Rings:");
firstLibrary.returnBook("The Lord of the Rings");
System.out.println();

// Print the titles of available from the first library
System.out.println("Books available in the first library:");
firstLibrary.printAvailableBooks();
}
}
/* 请在这里填写答案 */

完成后只需上传Library类。
### 输入样例:

在这里给出一组输入。例如:

in




### 输出样例:

在这里给出相应的输出。例如:

out
Library hours:
Libraries are open daily from 9am to 5pm.

Library addresses:
10 Main St.
228 Liberty St.

Borrowing The Lord of the Rings:
You successfully borrowed The Lord of the Rings
Sorry, this book is already borrowed.
Sorry, this book is not in our catalog.

Books available in the first library:
The Da Vinci Code
Le Petit Prince
A Tale of Two Cities

Books available in the second library:
No book in catalog

Returning The Lord of the Rings:
You successfully returned The Lord of the Rings

Books available in the first library:
The Da Vinci Code
Le Petit Prince
A Tale of Two Cities
The Lord of the Rings








答案:若无答案欢迎评论

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。