图书管理系统(Java)

1.设计要求

  1. 登录(普通用户、管理员)
  2. 普通用户支持的操作
    a)根据书名查询书籍
    d)借书
    c)还书
    d)退出
  3. 管理员支持的操作
    a)查询图书
    b)增加图书
    c)删除图书
    d)展示所有图书
    e)退出

2.类设计

2.1设计思路

在这里插入图片描述

2.2具体类

在这里插入图片描述

2.3整体流程

1.程序启动,登录系统并创建用户。
2.循环调用用户中 menu 方法,提示用户输入要操作的选项。
3.根据选项调用 DoAction 方法,执行到对应的 Action 中的逻辑。
4.根据 Action 中的 work 方法来完成最终的操作。

3.程序测试

3.1book包

Book类

package library.book;

public class Book {
   
    private String name;
    private String author;
    private int price;
    private String type; // 小说, 散文......
    private boolean isBorrowed; // 默认false 未借出

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

    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=" + isBorrowed +
                '}';
    }
}

BookList类

package library.book;

import library.book.Book;

//用来表示多本书
public class BookList {
   
    private Book[] books = new Book[100]; //相当于顺序表
    private int size = 0;//有效元素个数

    public BookList(){
   
        // 先默认添加几个数据进去, 方便后续测试
        books[0] = new Book("三国演义","罗贯中",100,"古典名著",false);
        size++;
        books[1] = new Book("西游记","吴承恩",120,"古典名著",false);
        size++;
        books[2] = new Book("金瓶梅","兰陵笑笑生",200,"古典名著",false);
        size++;
}

    public Book getBook(int pos){
   
        return books[pos];
    }

    public void setBook(int pos,Book book){
   
        books[pos] = book;
    }
    public int getSize() {
   
        return size;
    }

    public void setSize(int size
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,你需要一个图书管理系统Java代码,是吗?那么,下面是一个简单的图书管理系统Java代码示例,你可以根据自己的需求进行修改和完善。 ```java import java.util.Scanner; public class Library { public static void main(String[] args) { int n=0; Scanner sc=new Scanner(System.in); System.out.println("请输入图书数量:"); n=sc.nextInt(); Book[] books=new Book[n]; for(int i=0;i<n;i++){ System.out.println("请输入第"+(i+1)+"本书的信息:"); System.out.println("书名:"); String name=sc.next(); System.out.println("作者:"); String author=sc.next(); System.out.println("价格:"); double price=sc.nextDouble(); books[i]=new Book(name,author,price); } System.out.println("图书信息如下:"); for(int i=0;i<n;i++){ System.out.println(books[i].toString()); } } } class Book{ private String name; private String author; private double price; public Book(String name,String author,double price){ this.name=name; this.author=author; this.price=price; } 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 double getPrice(){ return price; } public void setPrice(double price){ this.price=price; } @Override public String toString(){ return "书名:"+name+",作者:"+author+",价格:"+price; } } ``` 这段代码实现了一个简单的图书管理系统,可以输入图书的数量和每本书的信息,然后将所有图书的信息输出。你也可以根据自己的需求进行修改和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值