shoppingcartitem.java
来自「《基于Eclipse的开源框架技术与实战》[第5章]随书源码」· Java 代码 · 共 77 行
JAVA
77 行
package com.free.struts.storefront.framework;
import com.free.struts.storefront.catalog.view.ItemDetailView;
/**
* <p>Title: Eclipse Plugin Development</p>
* <p>Description: Free download</p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: Free</p>
* @author gan.shu.man
* @version 1.0
*/
public class ShoppingCartItem {
public void setItem(ItemDetailView newItem) {
item = newItem;
calculateExtendedPrice();
}
public void setExtendedPrice(double newPrice) {
extendedPrice = newPrice;
}
public String getDescription() {
return item.getDescription();
}
public String getId() {
return item.getId();
}
public String getName() {
return item.getName();
}
public ShoppingCartItem(ItemDetailView item, int qty) {
this.item = item;
this.quantity = qty;
calculateExtendedPrice();
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int newQuantity) {
quantity = newQuantity;
calculateExtendedPrice();
}
public ItemDetailView getItem() {
return item;
}
public Double getUnitPrice() {
return item.getUnitPrice();
}
public double getExtendedPrice() {
return extendedPrice;
}
private void calculateExtendedPrice() {
if (item.getUnitPrice() != null) {
extendedPrice = item.getUnitPrice().doubleValue() * getQuantity();
}
}
// Extended price is unit price * qty
private double extendedPrice = 0.0;
private ItemDetailView item = null;
// Default qty to 1
private int quantity = 1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?