• Java《图书管理系统》练习


    书的对象(book)

    Book 书

    **package book;
    
    /**
     * 定义一本书
     */
    public class Book {
       
        private String name;// 书名
        private String author;//书的作者
        private int price;// 书的价格
        private String type;// 书的类型
        private boolean isBorrowed;//判断书是否有被借出去
    
        /**
         * 这里是没有初始化 isBorrowed
         * 原因:最开始一本书是默认没有被借出的
         * 如果没有初始化,boolean 默认是 flase
         */
        public Book(String name, String author, int price, String type) {
       
            this.name = name;
            this.author = author;
            this.price = price;
            this.type = type;
        }
    
        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 + '\'' +
                    ", 作者='" + author + '\'' +
                    ", 价格=" + price +
                    ", 类型='" + type + '\'' +
                    ((isBorrowed == true) ? " 以借出":" 未借出") +
                    '}';
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81

    BookList 书架

    package book;
    /**
     *  书架
     */
    
    public class BookList {
       
        // 用数组来当做书架,存根所以的书
        private  Book[] books = new Book[10];
        // 存储当前书架里有多少本书
        public int usedSize;
    
        // 通过构造方法来初始化数组(书架),给数组预存三本的书
        public BookList() {
       
           books[0] = new Book("三国演义","罗贯中",45,"小说");
           books[1] = new Book("西游记","吴承恩",46,"小说");
           books[2] = new Book("斗破苍穹","唐家三少",47,"小说");
           //书的数量
           this.usedSize = 3;
        }
    
        public int getUsedSize() {
       
            return usedSize;
        }
    
        public void setUsedSize(int usedSize) {
       
            this.usedSize = usedSize;
        }
        public Book getPos(int pos){
       
            return books[pos];
        }
    
        // 存储一本书到指定的位置,指的是最后的位置
        public void setBooks(Book book,
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
  • 相关阅读:
    【Spring】Bean 的作用域
    Dockerfile - USER 指令详解
    Apache POl
    长时平均功率谱
    B. Increasing
    论文网站有哪些?
    【cocos creator】编辑器里自动播放spine动画
    Gradle实现Maven中的dependencyManagement
    CHS寻址
    OpenCV DNN模块常用操作
  • 原文地址:https://blog.csdn.net/m0_66483195/article/details/126801837