用Java语言写一个图书管理系统
时间: 2023-03-01 13:40:53 浏览: 8
好的,我可以为您提供一些Java代码来实现一个图书管理系统。这个系统可以存储图书的信息,例如书名、作者、ISBN号等,并提供搜索、增加、删除、修改图书信息的功能。
```
import java.util.ArrayList;
import java.util.Scanner;
class Book {
private String name;
private String author;
private String ISBN;
public Book(String name, String author, String ISBN) {
this.name = name;
this.author = author;
this.ISBN = ISBN;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getISBN() {
return ISBN;
}
public void setISBN(String ISBN) {
this.ISBN = ISBN;
}
}
public class BookSystem {
private ArrayList<Book> books = new ArrayList<>();
public void addBook(Book book) {
books.add(book);
}
public void deleteBook(String ISBN) {
for (int i = 0; i < books.size(); i++) {
if (books.get(i).getISBN().equals(ISBN)) {
books.remove(i);
break;
}
}
}
public void updateBook(String ISBN, Book book) {
for (int i = 0; i < books.size(); i++) {
if (books.get(i).getISBN().equals(ISBN)) {
books.set(i, book);
break;
}
}
}
public void searchBook(String ISBN) {
for (int i = 0; i < books.size(); i++) {
if (books.get(i).getISBN().equals(ISBN)) {
System.out.println("书名: " + books.get(i).getName());
System.out.println("作者: " + books.get(i).getAuthor());
System.out.println("ISBN: " + books.get(i).getISBN());
break;
}
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
BookSystem bookSystem = new BookSystem();
while (true) {
System.out.println("请选择操作:");
System.out.println("1. 增
阅读全文