打字猴:1.700456211e+09
1700456211 private int price;
1700456212
1700456213 //书籍的作者
1700456214
1700456215 private String author;
1700456216
1700456217 //通过构造函数传递书籍数据
1700456218
1700456219 public NovelBook(String_name,int_price,String_author){
1700456220
1700456221 this.name=_name;
1700456222
1700456223 this.price=_price;
1700456224
1700456225 this.author=_author;
1700456226
1700456227 }
1700456228
1700456229 //获得作者是谁
1700456230
1700456231 public String getAuthor(){
1700456232
1700456233 return this.author;
1700456234
1700456235 }
1700456236
1700456237 //书籍叫什么名字
1700456238
1700456239 public String getName(){
1700456240
1700456241 return this.name;
1700456242
1700456243 }
1700456244
1700456245 //获得书籍的价格
1700456246
1700456247 public int getPrice(){
1700456248
1700456249 return this.price;
1700456250
1700456251 }
1700456252
1700456253 }
1700456254
1700456255 注意 我们把价格定义为int类型并不是错误,在非金融类项目中对货币处理时,一般取2位精度,通常的设计方法是在运算过程中扩大100倍,在需要展示时再缩小100倍,减少精度带来的误差。
1700456256
1700456257 书店售书的过程如代码清单6-3所示。
1700456258
1700456259 代码清单6-3 书店售书类
1700456260
[ 上一页 ]  [ :1.700456211e+09 ]  [ 下一页 ]