Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Servlet/JSP/JSF/JavaFX Script
打印话题 寄给朋友 订阅主题 |
作者 | 求助:java 语法问题 |
jayinseu
发贴: 3 |
于 2004-09-19 20:50
ShoppingCartItem scitem = (ShoppingCartItem) items.get(bookId); (ShoppingCartItem) 是什么意思?编译总是通不过 。。。。。。。。。。。。。。。。。。。。。。。。。。。 package mypack; import java.util.*; public class ShoppingCart { HashMap items = null; int numberOfItems = 0; public ShoppingCart() { items = new HashMap(); } public synchronized void add(String bookId, BookDetails book) { if(items.containsKey(bookId)) { ShoppingCartItem scitem = (ShoppingCartItem) items.get(bookId); scitem.incrementQuantity(); } else { ShoppingCartItem newItem = new ShoppingCartItem(book); items.put(bookId, newItem); } numberOfItems++; } public synchronized void remove(String bookId) { if(items.containsKey(bookId)) { ShoppingCartItem scitem = (ShoppingCartItem) items.get(bookId); scitem.decrementQuantity(); if(scitem.getQuantity() <= 0) items.remove(bookId); numberOfItems--; } } public synchronized Collection getItems() { return items.values(); } protected void finalize() throws Throwable { items.clear(); } public synchronized int getNumberOfItems() { return numberOfItems; } public synchronized double getTotal() { double amount = 0.0; for(Iterator i = getItems().iterator(); i.hasNext(); ) { ShoppingCartItem item = (ShoppingCartItem) i.next(); BookDetails bookDetails = (BookDetails) item.getItem(); amount += item.getQuantity() * bookDetails.getPrice(); } return roundOff(amount); } private double roundOff(double x) { long val = Math.round(x*100); // cents return val/100.0; } public synchronized void clear() { items.clear(); numberOfItems = 0; } } JAVA学习日子分享 |
话题树型展开 |
人气 | 标题 | 作者 | 字数 | 发贴时间 |
1429 | 求助:java 语法问题 | jayinseu | 1822 | 2004-09-19 20:50 |
1137 | Re:求助:java 语法问题 | lfrick | 42 | 2004-09-19 21:40 |
1069 | Re:求助:java 语法问题 | xiaoyu216 | 69 | 2004-09-24 14:24 |
1175 | Re:求助:java 语法问题 | scottding | 100 | 2004-09-29 09:39 |
已读帖子 新的帖子 被删除的帖子 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |