生成一个基于java的教材管理系统的代码
时间: 2024-06-11 15:08:07 浏览: 108
java的教材管理系统
很抱歉,我是一名语言模型AI,无法生成完整的基于java的教材管理系统代码。但我可以为您提供一个简单的代码框架,您可以根据自己的需求和具体情况进行修改和完善。
```
//教材类
class Book {
private String name; //教材名称
private String author; //作者
private String publisher; //出版社
private String ISBN; //书号
private int quantity; //库存量
private double price; //价格
//构造函数
public Book(String name, String author, String publisher, String ISBN, int quantity, double price) {
this.name = name;
this.author = author;
this.publisher = publisher;
this.ISBN = ISBN;
this.quantity = quantity;
this.price = price;
}
//getter和setter方法
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 getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getISBN() {
return ISBN;
}
public void setISBN(String ISBN) {
this.ISBN = ISBN;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
//教材管理类
class BookManager {
private List<Book> books; //教材列表
//构造函数,初始化教材列表
public BookManager() {
books = new ArrayList<>();
}
//添加教材
public void addBook(Book book) {
books.add(book);
}
//删除教材
public void deleteBook(String ISBN) {
for (Book book : books) {
if (book.getISBN().equals(ISBN)) {
books.remove(book);
break;
}
}
}
//查找教材
public Book findBook(String ISBN) {
for (Book book : books) {
if (book.getISBN().equals(ISBN)) {
return book;
}
}
return null;
}
//修改教材信息
public void modifyBook(String ISBN, Book newBook) {
for (Book book : books) {
if (book.getISBN().equals(ISBN)) {
book.setName(newBook.getName());
book.setAuthor(newBook.getAuthor());
book.setPublisher(newBook.getPublisher());
book.setQuantity(newBook.getQuantity());
book.setPrice(newBook.getPrice());
break;
}
}
}
//列出所有教材
public void listAllBooks() {
for (Book book : books) {
System.out.println(book.getName() + " " + book.getAuthor() + " " + book.getPublisher() + " " + book.getISBN() + " " + book.getQuantity() + " " + book.getPrice());
}
}
}
//测试类
public class Test {
public static void main(String[] args) {
BookManager bookManager = new BookManager();
//添加教材
Book book1 = new Book("Java编程思想", "Bruce Eckel", "机械工业出版社", "9787111407010", 100, 79.00);
bookManager.addBook(book1);
//查找教材
Book book = bookManager.findBook("9787111407010");
if (book != null) {
System.out.println("找到了教材:" + book.getName());
} else {
System.out.println("没有找到教材");
}
//修改教材信息
Book newBook = new Book("Java编程思想(第二版)", "Bruce Eckel", "机械工业出版社", "9787111407010", 50, 89.00);
bookManager.modifyBook("9787111407010", newBook);
//删除教材
bookManager.deleteBook("9787111407010");
//列出所有教材
bookManager.listAllBooks();
}
}
```
阅读全文