可以在優化嗎?

可以在優化嗎?

package com.imooc.animal;

public class Book {
	private String bookTitle;
	private String Author;
	private String  publisher;
	private double price;

	public Book(String bookTitle, String author, String publisher, double price) {
		this.setbookTitle(bookTitle);
		this.setAuthor(author);
		this.setPublisher(publisher);
		this.setPrice(price);

	}

	public void setbookTitle(String bookTitle) {
		this.bookTitle = bookTitle;
	}

	public String getbookTitle() {
		return "書名:" + bookTitle;
	}

	public String getAuthor() {
		return "作者" + Author;
	}

	public void setAuthor(String author) {
		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) {
		if (price < 10) {
			System.out.println("圖書價格最低10元");
		price=10;
		this.price =price;
	}else {	
			this.price = price;
	}
	}
	public void Print() {
		String st =this.getbookTitle()+"\n"+this.getAuthor()+
				"\n"+this.getPublisher()+"\n價格:"+this.getPrice();
		System.out.println(st);
	}

}

第二類

package com.imooc.animal;

public class BookTest {

	public static void main(String[] args) {
		Book bo = new Book("紅樓夢", "曹雪", "人民出版", 11);
		Book bo1 = new Book("小李飛刀", "古龍", "中國出版", 55.5);

		bo.Print();
		System.out.println("=====================");
		bo1.Print();

	}
}


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,

程序思路简洁,写的很棒,无需优化哦~

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师