shoppingcartitem.java
来自「采用Struts框架做的网上啤酒买卖系统」· Java 代码 · 共 67 行
JAVA
67 行
package com.cavaness.beer4all.framework;import com.cavaness.beer4all.catalog.view.ItemView;//购物车中的商品类public class ShoppingCartItem { //设置商品,计算此类商品总价格 public void setItem(ItemView newItem) { item = newItem; calculateExtendedPrice(); } //设置此类商品总价格 public void setExtendedPrice(double newPrice) { extendedPrice = newPrice; } //获取商品的描述信息 public String getDescription() { return item.getDescription(); } //获取商品编号 public Integer getId() { return item.getOid(); } //获取商品名 public String getName() { return item.getName(); } //带商品及商品数量初始化购物车中的商品类 public ShoppingCartItem(ItemView item, int qty) { this.item = item; this.quantity = qty; calculateExtendedPrice(); } //获取商品数量 public int getQuantity() { return quantity; } //设置商品数量 public void setQuantity(int newQuantity) { quantity = newQuantity; calculateExtendedPrice(); } //获取商品信息 public ItemView getItem() { return item; } //获取商品单价 public Double getUnitPrice() { return item.getPrice(); } //获取此类商品总价格 public double getExtendedPrice() { return extendedPrice; } //计算此类商品总价格 private void calculateExtendedPrice() { if ( item.getPrice() != null ){ extendedPrice = item.getPrice().doubleValue() * getQuantity(); } } private double extendedPrice = 0.0; //此类商品总价格 private ItemView item = null; //商品 private int quantity = 1; //数量}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?