图书类

********8、 设计一个图书类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 String price;
        public Book(){
        	
        }
        public Book(String bi,String bn,String au,String pu,String pr){
        	this.bookId=bi;
        	this.bookName=bn;
        	this.author=au;
        	this.publisher=pu;
        	this.price=pr;
        	
        }
        void show()
        {
        	System.out.println("书籍编号:"+this.bookId+"书名:"+this.bookName+"作者:"+this.author+"出版单位:"+this.publisher+"价格:"+this.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 String getPrice() {
			return price;
		}
		public void setPrice(String price) {
			this.price = price;
		}
        

public class TestBook {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
 Book book=new Book("20135850","赵大逼正传!","王爷  ","王爷税务局    ","价值连城     ");
 book.show();
	}

}

你可能感兴趣的:(类,设计)