Java图书管理系统小练习


学习了类和对象,封装,继承,多态,抽象类和接口后,来做一个小练习。

系统功能

  1. 用户登录
  2. 用户分为管理员和普通用户
  3. 管理员和普通用户有不同的功能
    在这里插入图片描述

基础框架

book包

在这里插入图片描述

Book类
这个类放图书的属性,还有属性的get和set方法,以及toString方法输出图书的属性

package book;

public class Book {
   
    private String name;//书名
    private String author;//作者
    private String type;//类型
    private double price;//价格
    private boolean isBorrowed;//是否被借出
	
	//不用给isBorrowed赋初值,默认为false
    public Book(String name, String author, String type, double price) {
   
        this.name = name;
        this.author = author;
        this.type = type;
        this.price = price;
    }
    
    //重写toString
    @Override
    public String toString() {
   
        return "Book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", type='" + type + '\'' +
                ", price=" + price +
                ", isBorrowed=" + isBorrowed +
                '}';
    }
    
    //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 String getType() {
   
        return type;
    }

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

    public double getPrice() {
   
        return price;
    }

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

    public boolean isBorrowed() {
   
        return isBorrowed;
    }

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

BookList类
这个类放Book类数组
数组默认大小是10

package book;

public class BookList {
   

    private Book[] books = new Book[10];
    private int usedSize;//记录当前books数组当中 有多少本书
	
	//这里默认放了3本书
    public BookList() {
   
        books[0] = new Book("三国演义","罗贯中","小说",69);
        books[1] = new Book("西游记","吴承恩","小说",79);
        books[2] = new Book("红楼梦","曹雪芹","小说",59);
        this.usedSize = 3;
    }
    
    public Book getBook(int pos) {
   
        return this.books[pos];
    }
    
    //这里两个setBook方法构成重载
    //增加图书功能要用到
    public void setBook(Book book) {
   
        this.books[usedSize] = book;
    }
    
    //删除图书时,将后面的图书往前移会用到
    public void setBook(int pos,Book book) {
   
        this.books[pos] = book;
    }

    public int getUsedSize() {
   
        return usedSize;
    }

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

operate包

在这里插入图片描述

这个包

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值