图书系统的创建(一)——日记

创建图书管理系统大致分为四个部分,图书、使用者、操作系统,运行窗口等四个方面,我们今天先做图书这一部分。

对于图书,我们首先要创建它的属性,即书名、价格、作者、图书类型等等,

public String name;
public String author;
public String price;
public String type;
public boolean condition;

此外,我们要得到这些成员属性,会用到get和set方法,以及本身的构造方法。(get~与set~是为了将这些独立的信息串起来)

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

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

写出这些基本的变量后,我们就要存储具体的图书,我们可以建立一个Booklist书架来存储我们的图书,这样一本一本的图书的储存肯定要用的数组,所以,我们需要建立一个数组并将它初始化,当然也需要将独立的书本通过get获得。

this.books[0] = new Book("三国演义","罗贯中",20,"小说");
this.books[1] = new Book("西游记","吴承恩",21,"小说");
this.books[2] = new Book("红楼梦","曹雪芹",22,"小说");

 book代码:

package book;

public class Book {
    public String name;
    public String author;
    public int price;
    public String type;
    public boolean condition;

    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;
    }

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price='" + price + '\'' +
                ", type='" + type + '\'' +
                ((condition == true) ? "借出" : "未借出") +
                '}';
    }
}

 Bookshelf代码:


public class Bookshelf {
    public Book[] books = new Book[10] ;
    public Bookshelf(){
        this.books[0] = new Book("三国演义","罗贯中",20,"小说");
        this.books[1] = new Book("西游记","吴承恩",21,"小说");
        this.books[2] = new Book("红楼梦","曹雪芹",22,"小说");

    }

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

    public void setBooks(int pos,Book book) {
        this.books[pos] = book;
    }

    public Book[] getBooks() {
        return books;
    }

    public void setBooks(Book[] books) {
        this.books = books;
    }
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值