一个简单的图书管理系统

这是一个简单的图书管理系统,包括Book、BookList、IOperation以及不同操作类如AddOperation、BorrowOperation等的实现。用户类分为AdminUser和NormalUser,系统通过main函数运行。设计旨在提高程序效率,未来将扩展更多功能。
摘要由CSDN通过智能技术生成


简单的图书管理系统

二、各个类的实现

1.book类

(1)Book

package book;
public class Book {
   
    private String name;//书名
    private String author;//作者
    private int price;//价格
    private String type;//类型
    private boolean isBorrowed;//是否借出

    public Book(String name, String author, int price, String type) {
   
        this.name = name;
        this.author = author;
        this.price = price;
        this.type = type;
    }

    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 int getPrice() {
   
        return price;
    }

    public void setPrice(int price) {
   
        this.price = price;
    }

    public String getType() {
   
        return type;
    }

    public void setType(String type) {
   
        this.type = type;
    }

    public boolean isBorrowed() {
   
        return isBorrowed;
    }

    public void setBorrowed(boolean borrowed) {
   
        isBorrowed = borrowed;
    }

    @Override
    public String toString() {
   
        return "Book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                ", type='" + type + '\'' +
                ((isBorrowed == true) ? " 已经被借出 " : " 未被借出 ") +
                '}';
    }
}

(2)BookList

package book;

public class BookList {
   
    private Book[] books = new Book[10];
    private int usedSize;

    public BookList() {
   
        books[0] = new Book("三国演义","罗贯中",17,"小说");
        books[1] = new Book("西游记","吴承恩",47,"小说");
        books[2] = new Book("水浒传","施耐庵",37,"小说");
        this.usedSize = 3;
    }

    public int getUsedSize() {
   
        return usedSize;
    }

    public void setUsedSize(int usedSize) {
   
        this.usedSize = usedSize;
    }

    //获取到pos位置的一本书
    public Book getPos(int pos) {
   
        return this.books[pos];
    }

    //设置Pos下标为一本书->[添加一本书]
    public void setBook(int pos,Book book) {
   
        this.books[pos] = book;
    }

  • 15
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
以下是一个简单图书管理系统的 C 语言实现,包括添加图书、查找图书、删除图书和显示所有图书的功能。 ```c #include <stdio.h> #include <string.h> #define MAX_BOOKS 100 // 图书结构体 struct Book { char id[10]; // 图书编号 char title[50]; // 图书标题 char author[30]; // 图书作者 int year; // 出版年份 }; // 图书数组 struct Book books[MAX_BOOKS]; int num_books = 0; // 当前图书数量 // 添加图书 void add_book() { if (num_books >= MAX_BOOKS) { printf("Sorry, the library is full.\n"); return; } struct Book book; printf("Please enter book ID: "); scanf("%s", book.id); printf("Please enter book title: "); scanf("%s", book.title); printf("Please enter book author: "); scanf("%s", book.author); printf("Please enter publication year: "); scanf("%d", &book.year); books[num_books++] = book; printf("Book added successfully.\n"); } // 查找图书 void find_book() { char id[10]; printf("Please enter book ID: "); scanf("%s", id); for (int i = 0; i < num_books; i++) { if (strcmp(id, books[i].id) == 0) { printf("Book found:\n"); printf("ID: %s\n", books[i].id); printf("Title: %s\n", books[i].title); printf("Author: %s\n", books[i].author); printf("Publication year: %d\n", books[i].year); return; } } printf("Sorry, book not found.\n"); } // 删除图书 void delete_book() { char id[10]; printf("Please enter book ID: "); scanf("%s", id); for (int i = 0; i < num_books; i++) { if (strcmp(id, books[i].id) == 0) { for (int j = i; j < num_books - 1; j++) { books[j] = books[j+1]; } num_books--; printf("Book deleted successfully.\n"); return; } } printf("Sorry, book not found.\n"); } // 显示所有图书 void display_books() { printf("Library contains %d books:\n", num_books); for (int i = 0; i < num_books; i++) { printf("ID: %s\n", books[i].id); printf("Title: %s\n", books[i].title); printf("Author: %s\n", books[i].author); printf("Publication year: %d\n", books[i].year); } } int main() { int choice; do { printf("\nLibrary Management System\n"); printf("1. Add book\n"); printf("2. Find book\n"); printf("3. Delete book\n"); printf("4. Display all books\n"); printf("0. Exit\n"); printf("Please enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: add_book(); break; case 2: find_book(); break; case 3: delete_book(); break; case 4: display_books(); break; case 0: printf("Goodbye!\n"); break; default: printf("Invalid choice.\n"); } } while (choice != 0); return 0; } ``` 注意:此为简单的实现,未考虑并发、安全性等问题。在实际开发中需要进行更加严谨的设计和实现。
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值