⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shoppingcartitem.java

📁 网上商店 新增功能: 1
💻 JAVA
字号:
package netstore.framework;

import netstore.businessobjects.Item;

/**
 * This wraps the actual item class to help decouple the shopping cart from
 * the actual items it stores.
 */
public class ShoppingCartItem {
  public void setItem(Item newItem) {
    item = newItem;
    calculateUnitPrice();
  }
  public void setUnitPrice(double newPrice) {
    unitPrice = newPrice;
  }
  public String getDescription() {
    return item.getDescription();
  }
  public Long getId() {
    return item.getId();
  }
  public String getName() {
    return item.getName();
  }
  public ShoppingCartItem(Item item, int qty) {
    this.item = item;
    this.quantity = qty;
    calculateUnitPrice();
  }
  public int getQuantity() {
    return quantity;
  }
  public void setQuantity(int newQuantity) {
    quantity = newQuantity;
    calculateUnitPrice();
  }
  public Item getItem() {
    return item;
  }
  public Double getBasePrice() {
    return item.getBasePrice();
  }
  public double getUnitPrice() {
    return unitPrice;
  }
  /**
   * unitPrice已经是 "单价*数量"
   *
   */
  private void calculateUnitPrice() {
    if ( item.getBasePrice() != null ){
      unitPrice = item.getBasePrice().doubleValue() * getQuantity();
    }
  }

  // Unit price is base price * qty
  private double unitPrice = 0.0;
  private Item item = null;

  // Default qty to 1
  private int quantity = 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -