可以在優化嗎?
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();
}
}0
收起
正在回答
1回答
同学你好,
程序思路简洁,写的很棒,无需优化哦~
如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
1. Java 零基础入门
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星