Java——面向对象练习(图书管理系统的实现)

本文介绍了一个简单的图书管理系统,使用Java面向对象编程实现。系统包括图书类、图书列表类和多个操作类,支持管理员和普通用户的不同功能。

Java——面向对象练习(图书管理系统的实现)


  在前面一段时间里,学习了 Java 面向对象的相关内容:包的使用、继承、多态、抽象类、接口等知识,现在为了巩固我们所学习的知识,接下来我们将从零到有实现一个简单版的图书管理系统的代码实现。


一、实现效果展示


(1)功能简介


(2)登陆界面

在这里插入图片描述

(3)菜单界面

在这里插入图片描述

(4)功能展示


1.显示图书
在这里插入图片描述

2.新增图书

在这里插入图片描述

3.删除图书

在这里插入图片描述

4.查找图书

在这里插入图片描述

5.借阅图书

在这里插入图片描述

6.归还图书

在这里插入图片描述

二、具体代码实现


1.类的设计


  我们通过这个管理系统的功能简介等,可以知道我们需要设计的几个类


(1)创建图书相关的类


先创建 package book

创建 Book 类, 表示一本书
在这里插入图片描述

package book;

public class Book {
   
   

    private String name;
    private String author;
    private int price;
    private String type;
    private boolean 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;
    }

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

    @Override
    public String toString() {
   
   
        return "Book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                ", type='" + type + '\'' +
                ", isBorrowed=" + isBorrowed +
                '}';
    }
}

  这个书的类中,有书的各种属性:书名、作者、价格、类别、借阅情况,同时将这些属性都封装起来。

创建 BookList 类, 用来保存 N 本书.

package book;

public class BookList {
   
   

    private Book[] books = new Book[100];
    private int usedSize;


    public BookList(){
   
   

        //默认有四本书

        books[0] = new Book("西游记","吴承恩",10,"小说" );
        books[1] = new Book("水浒传","施耐庵",20,"小说" );
        books[2] = new Book("红楼梦","曹雪芹",10,"小说" );
        books[3] = new Book("三国演义","罗贯中",10,"小说" );
        this.usedSize  = 4;
    }

    public Book getBooks(int pos) {
   
   
        return this.books[pos];
    }

    public void setBooks(int pos,Book book) {
   
   
        //默认放到顺序表的最后
        this.books[pos] = book;
    }

    public int getUsedSize() {
   
   
        return usedSize;
    }

    public void setUsedSi
评论 49
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

RAIN 7

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

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

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

打赏作者

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

抵扣说明:

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

余额充值