图书管理系统(Java顺序表实现)

一、简介

    实现此项目的目的是巩固并理解前面的知识点:类,抽象类,封装,继承,多态,接口等

二、核心需求

管理端
  查阅书籍
  增加书籍
  删除书籍
  打印书籍列表
  退出系统

用户端
  查询书籍
  借阅书籍
  归还书籍
  打印书籍列表
  退出系统

三、类的设计

1. 创建图书类

    图书类中包含图书的名称,价格,类型,作者和是否被借出等信息,并生成构造方法,Getter()和Setter()方法,toString方法(注意成员变量应该尽可能使用private关键字修饰)

public class Book {
   
    private String name;
    private double price;
    private String type;
    private String author;
    private boolean isBorrowed;

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

    public String getName() {
   
        return name;
    }

    public void setName(String name) {
   
        this.name = name;
    }

    public double getPrice() {
   
        return price;
    }

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

    public String getType() {
   
        return type;
    }

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

    public String getAuthor() {
   
        return author;
    }

    public void setAuthor(String author) {
   
        this.author = author;
    }

    public boolean isBorrowed() {
   
        return isBorrowed;
    }

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

    @Override
    public String toString() {
   
        return "Book{" +
                "name='" + name + '\'' +
                ", price=" + price +
                ", type='" + type + '\'' +
                ", author='" + author + '\'' +
                ", 状态:" +((isBorrowed) ? "已借出":"未借出")+
                '}';
    }
}
2. 创建图书列表类

    图书列表类用于存放图书,我们可以先在列表中初始化几本书以方便后续测试

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

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

    public int getUsedSize() {
   
        return usedSize;
    }

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

    public Book getBook(int pos){
   
        return
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhanglf6699

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值