1700456622
1700456623
这也很简单,实现IComputerBook就可以,而BookStore类没有做任何的修改,只是在static静态模块中增加一条数据,如代码清单6-10所示。
1700456624
1700456625
代码清单6-10 书店销售计算机书籍
1700456626
1700456627
public class BookStore{
1700456628
1700456629
private final static ArrayList<IBook>bookList=new ArrayList<IBook>();
1700456630
1700456631
//static静态模块初始化数据,实际项目中一般是由持久层完成
1700456632
1700456633
static{
1700456634
1700456635
bookList.add(new NovelBook(“天龙八部”,3200,“金庸”));
1700456636
1700456637
bookList.add(new NovelBook(“巴黎圣母院”,5600,“雨果”));
1700456638
1700456639
bookList.add(new NovelBook(“悲惨世界”,3500,“雨果”));
1700456640
1700456641
bookList.add(new NovelBook(“金瓶梅”,4300,“兰陵笑笑生”));
1700456642
1700456643
//增加计算机书籍
1700456644
1700456645
bookList.add(new ComputerBook(“Think in Java”,4300,“Bruce Eckel”,”
1700456646
1700456647
编程语言”));
1700456648
1700456649
}
1700456650
1700456651
//模拟书店买书
1700456652
1700456653
public static void main(String[]args){
1700456654
1700456655
NumberFormat formatter=NumberFormat.getCurrencyInstance();
1700456656
1700456657
formatter.setMaximumFractionDigits(2);
1700456658
1700456659
System.out.println(”–––—书店买出去的书籍记录如下:–––—”);
1700456660
1700456661
for(IBook book:bookList){
1700456662
1700456663
System.out.println(“书籍名称:”+book.getName()+”\t书籍作者:
1700456664
1700456665
“+book.getAuthor()+”\t书籍价格:”+formatter.format
1700456666
1700456667
(book.getPrice()/100.0)+“元”);
1700456668
1700456669
}
1700456670
1700456671
}
[
上一页 ]
[ :1.700456622e+09 ]
[
下一页 ]