关于这个题目,下面代码思路正确吗?

来源:1-7 编程练习

小太阳哦

2019-05-05 18:22:34

public class Book {

private String bookname;

     private String write;

     private double price;

     private String chubshe;

public String getBookname(  ) {

return bookname;

}

public String getWrite( ) {

return write;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

if(price<10) {

System.out.println("价格最低10元");

price=10;

}

this.price = price;

}

public String getChubshe() {

return chubshe;

}

public void setChubshe(String chubshe) {

this.chubshe = chubshe;

}

public Book(String bookname,String write ) {

this.bookname=bookname;

this.write=write;

}

public String info() {

String st="书名:"+this.getBookname()+"\n作者:"+this.getWrite()+"\n出版社"+

this.getChubshe()+"\n价格"+this.getPrice()+"元";

return st;

}

public static void main(String[] args){

Book we=new Book("红楼梦"," 曹雪芹");

Book we1=new Book("小李飞刀","古龙");

we.setChubshe("人民文学出版社");

we.setPrice(9);

we1.setChubshe("中国长安出版社");

we1.setPrice(55.5);

System.out.println(we.info());

System.out.println("=======================");

System.out.println(we1.info());

}

     

}


写回答

1回答

吃吃吃鱼的猫

2019-05-05

同学你好,思路正确,写的很棒哦~

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

1

0 学习 · 11489 问题

查看课程