代码输出书名和作者下面是红线
public class Book {
//私有属性:书名、作者、出版社、价格
private String title;
private String author;
private String publishing;
private double price;
public Book(String title,String author,String publishing,double price){
this.title=title;
this.author=author;
this.setPublishing(publishing);
this.setPrice(price);
}
public String getPublishing() {
return publishing;
}
public void setPublishing(String publishing) {
this.publishing = publishing;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
if(price<=10){
System.out.println("图书价格最低10元");
this.price=10;
}else{
this.price=price;
}
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public void setTitle(String title) {
this.title = title;
}
public void setAuthor(String author) {
this.author = author;
}
public class BookTest {
public static void main(String[] args) {
//实例化第一本书,四参构造方法
Book one=new Book("红楼梦","曹雪芹","人名文学出版社",10.0);
//实例化第二本书,四参构造方法
Book two = new Book("小李飞刀","古龙","中国长安出版社",55.5);
//第一第二本书描述信息方法
System.out.println("书名:"+one.getTitle());
System.out.println("作者:"+one.getAuthor());
System.out.println("出版社:"+one.getPublishing());
System.out.println("价格:"+one.getPrice());
System.out.println("===========================================");
System.out.println("书名:"+two.getTitle());
System.out.println("作者:"+two.getAuthor());
System.out.println("出版社:"+two.getPublishing());
System.out.println("价格:"+two.getPrice());
}
}
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 5461 份
- 解答问题 7238 个
此次推出的专题为Android攻城狮培养计划的第一部分语法与界面基础篇,将带大家从0开始学习Android开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星