Java图书类

1、 设计一个图书类Book,该Book类具有属性:书籍编号(bookId),书名(bookName),作者(author),出版单位(publisher),单价(price)。

a) 要求属性私有,生成其共有的get/set 方法;

b) 具有方法:show():该方法内显示给书籍的详细信息

c) 在创建一个Book对象的同时给该对象各属性赋初值。(带参构造)

d) 编写测试类TestBook,实现创建一个Book对象book,打印出该书的详细信息。

public class Book {
	private String bookId;
	private String bookName;
	private String author;
	private String publisher;
	private double price;
	public Book(){}
	public Book(String bookId,String bookName,String author,String publisher,double price){
		this.bookId=bookId;
		this.bookName=bookName;
		this.author=author;
		this.publisher=publisher;
		this.price=price;	
	}
	public void show(){
		System.out.println(bookId);
		System.out.println(bookName);
		System.out.println(author);
		System.out.println(publisher);
		System.out.println(price);
	}
	public String getBookId() {
		return bookId;
	}
	public void setBookId(String bookId) {
		this.bookId = bookId;
	}
	public String getBookName() {
		return bookName;
	}
	public void setBookName(String bookName) {
		this.bookName = bookName;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public String getPublisher() {
		return publisher;
	}
	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	
}


 

public class BookTest extends Book {
	public static void main(String[] args){
		Book book=new Book("11111111","《《十万个为什么》》","不明","清华出版社",20);
		book.show();
	}
}


 

你可能感兴趣的:(Java图书类)