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

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

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回答

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

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

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

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

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

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

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