成语大全网 - 成语解释 - 用java实现的电子词典

用java实现的电子词典

class Book { //定义Book类

private String bookName; //书名

private String author; //作者

private String publisher; //出版社

private String publishDate; //出版日期

public Book(String bookName, String author, String publisher, String publishDate) { //构造方法

this.setBookName(bookName);

this.setAuthor(author);

this.setPublisher(publisher);

this.setPublishDate(publishDate);

}

public void setBookName(String bookName) {

this.bookName = bookName;

}

public String getBookName() {

return bookName;

}

public void setAuthor(String author) {

this.author = author;

}

public String getAuthor() {

return author;

}

public void setPublisher(String publisher) {

this.publisher = publisher;

}

public String getPublisher() {

return publisher;

}

public void setPublishDate(String publishDate) {

this.publishDate = publishDate;

}

public String getPublishDate() {

return publishDate;

}

public String toString() {

return "|--书名:" + this.getBookName() + "\n\t" + "|--作者:" + this.getAuthor() +

"\n\t" + "|--出版社:" + this.getPublisher() + "\n\t" + "|--出版日期:" + this.getPublishDate();

}

}

public class BookShelf {

public static void main(String[] args) {

Book b1 = new Book("书名1", "作者1", "出版社1", "2010-01-01");

System.out.println(b1);

Book b2 = new Book("书名2", "作者2", "出版社2", "2010-02-02");

System.out.println(b2);

Book b3 = new Book("书名3", "作者3", "出版社3", "2010-03-03");

System.out.println(b3);

}

}