javaOOP面向对象十二章书虫阅读器代码
时间: 2024-05-02 13:15:13 浏览: 191
Java OOP面向对象十二章书虫阅读器代码是一个用于管理和操作图书馆的应用程序。以下是该应用程序的主要功能和代码示例:
1. 图书类(Book):
- 属性:书名(title)、作者(author)、出版社(publisher)、ISBN号(isbn)
- 方法:获取书名、获取作者、获取出版社、获取ISBN号
```java
public class Book {
private String title;
private String author;
private String publisher;
private String isbn;
public Book(String title, String author, String publisher, String isbn) {
this.title = title;
this.author = author;
this.publisher = publisher;
this.isbn = isbn;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public String getPublisher() {
return publisher;
}
public String getIsbn() {
return isbn;
}
}
```
2. 图书馆类(Library):
- 属性:图书列表(books)
- 方法:添加图书、删除图书、查找图书、显示所有图书
```java
import java.util.ArrayList;
import java.util.List;
public class Library {
private List<Book> books;
public Library() {
books = new ArrayList<>();
}
public void addBook(Book book) {
books.add(book);
}
public void removeBook(Book book) {
books.remove(book);
}
public Book findBook(String title) {
for (Book book : books) {
if (book.getTitle().equals(title)) {
return book;
}
}
return null;
}
public void displayBooks() {
for (Book book : books) {
System.out.println("Title: " + book.getTitle());
System.out.println("Author: " + book.getAuthor());
System.out.println("Publisher: " + book.getPublisher());
System.out.println("ISBN: " + book.getIsbn());
System.out.println("----------");
}
}
}
```
以上是一个简单的图书馆管理系统的代码示例,包括了图书类和图书馆类。你可以根据需求进行扩展和修改。
阅读全文