【Java】图书管理系统,完整版+源代码!!!
由于提供完整的图书管理系统源码超过了答案字数限制,我将提供一个简化版本的图书管理系统的核心功能代码,例如添加图书、查看图书列表等。
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class BookManagementSystem {
private List<Book> bookList = new ArrayList<>();
public static void main(String[] args) {
BookManagementSystem bookSystem = new BookManagementSystem();
bookSystem.run();
}
public void run() {
Scanner scanner = new Scanner(System.in);
boolean isRunning = true;
while (isRunning) {
System.out.println("请选择操作:");
System.out.println("1. 添加图书");
System.out.println("2. 查看图书");
System.out.println("3. 退出系统");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addBook(scanner);
break;
case 2:
listBooks();
break;
case 3:
isRunning = false;
break;
default:
System.out.println("无效的选项,请重新输入。");
break;
}
}
scanner.close();
}
private void addBook(Scanner scanner) {
System.out.println("请输入图书名称:");
String name = scanner.nextLine();
System.out.println("请输入图书作者:");
String author = scanner.nextLine();
Book book = new Book(name, author);
bookList.add(book);
System.out.println("图书添加成功!");
}
private void listBooks() {
if (bookList.isEmpty()) {
System.out.println("图书列表为空。");
return;
}
System.out.println("图书列表:");
for (Book book : bookList) {
System.out.println(book.getName() + " | " + book.getAuthor());
}
}
static class Book {
private String name;
private String author;
public Book(String name, String author) {
this.name = name;
this.author = author;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
}
}
这段代码提供了一个简单的图书管理系统的核心功能实现,包括添加图书、查看图书列表。它使用了ArrayList
来存储图书信息,并通
评论已关闭