JAVA学习记录(十三)—— 图书管理系统

该系统总共有以下这么多个部分

在这里插入图片描述

一、book文件夹下:
  • Book中有每一本书得信息,与这些信息的Get和Set方法,还有对于书的toString方法
package 一月十八日.图书管理系统.book;

public class Book {
   
   
    private String name;    //书名
    private String author;  //作者
    private int price;      //价格
    private String type;    //类型
    private boolean status; //状态 -》 默认未借出

    // 构造方法
    public Book(String name, String author, int price, String type) {
   
   
        this.name = name;
        this.author = author;
        this.price = price;
        this.type = type;
    }
    // Get、Set方法
    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 isStatus() {
   
   
        return status;
    }
    public void setStatus(boolean status) {
   
   
        this.status = status;
    }
    // toString方法
    @Override
    public String toString() {
   
   
        return "book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                ", type='" + type + '\'' +
                //", status=" + status +
                ((status == true) ? " 借出 " : " 未借出 ") +
                '}';
    }
}
  • BookList这里相当于一个书架,其实是由顺序表的形式实现的
package 一月十八日.图书管理系统.book;

public class BookList {
   
   
    // 书架,就相当于一个顺序表
    private Book[] books;
    private int usedSize;

    // 提供一个构造方法
    public BookList() {
   
   
        this.books = new Book[10]; // 最多放10本书
        // 先给里面放上三本书
        books[0] = new Book("三国演义","罗贯中",72,"小说");
        books[1] = new Book("西游记","吴承恩",52,"小说");
        books[2] = new Book("水浒传","施耐庵",62,"小说");
        this.usedSize = 3;
    }
    // 尾插法
    public void setBooks(int pos, Book book){
   
   
        this.books[pos] = book;
    }

    public Book getBook(int pos){
   
   
        return this.books[pos];
    }
    public int getUsedSize() {
   
   
        return usedSize;
    }
    public void setUsedSize(int usedSize) {
   
   
        this.usedSize = usedSize;
    }
}
二、Operation文件夹下:
  • 这里实现了诸多方法,都是对顺序
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值