请问我的思路是否正确呢?
来源:1-7 编程练习
慕沐3198375
2019-09-08 21:24:20
package com.project;
public class Book {
//成员属性
private String name;
private String author;
private String publishHouse;
private double price;
//带参构造方法
public Book(String name,String author,String publishHouse,double price) {
this.author=author;
this.name=name;
this.setPrice(price);
this.setPublishHouse(publishHouse);
}
public String getPublishHouse() {
return publishHouse;
}
public void setPublishHouse(String publishHouse) {
this.publishHouse = publishHouse;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
if(price<10) {
System.out.println("图书价格最低10元");
this.price=10.0;}
else
this.price = price;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
public void infoIntroduce() {
System.out.println("书名:"+this.getName());
System.out.println("作者:"+this.getAuthor());
System.out.println("出版社:"+this.getPublishHouse());
System.out.println("价格:"+this.getPrice());
}
}
package com.project;
public class BookTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Book one = new Book("红楼梦","曹雪芹","人民文学出版社",1);
one.infoIntroduce();
System.out.println("================================");
Book two = new Book("小李飞刀","古龙","中国长安出版社",55.5);
two.infoIntroduce();
}
}
1回答
同学你好,代码完成的很棒!思路清晰!继续努力!
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
相似问题