Program.java:
package com.xy6.interview;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import com.xy6.interview.util.ProductFreeTaxTypeUtil;
/**
* 主程序
*
* @author daxiang
* @since 2014-07-17
*/
public class Program {
private static Logger logger = Logger.getLogger(Program.class);
/**
* 程序入口
*
* @param args
*/
public static void main(String[] args) {
String strLog4jFile = "G:/PROGRAM/j2ee/workspace/DemoInterview2/com/xy6/interview/config/log4j.properties";
PropertyConfigurator.configure(strLog4jFile);
ProductFreeTaxTypeUtil.init();
calculateResult();
}
/**
* 展示各购物车的总税额和总价
*/
public static void calculateResult(){
IProductService productService = new ProductService();
String strFilePath;
ProductResultForm resultForm;
strFilePath = "G:/PROGRAM/j2ee/workspace/DemoInterview2/com/xy6/interview/data/";
String[] strXmlFile = new String[]{"case1.xml","case2.xml","case3.xml"};
for(String strXmlFilePath : strXmlFile){
resultForm = new ProductResultForm();
resultForm = productService.calcProductPrice(strFilePath + strXmlFilePath);
logger.info(strXmlFilePath + ":");
logger.info("total:" + resultForm.getBdTotalPrice().toString());
logger.info("taxes:" + resultForm.getBdTotalTax().toString());
logger.info("");
}
}
}
ProductForm.java:
package com.xy6.interview;
import java.math.BigDecimal;
/**
* 商品信息表单类
*
* @author zhang
* @since 2014-07-17
*/
public class ProductForm {
/** 商品名称 */
private String name;
/** 商品数量 */
private int count;
/** 商品单价 */
private BigDecimal unitPrice;
/** 商品类型 */
private String type;
/** 是否进口 */
private boolean imported;
/** 商品价格 */
private BigDecimal itemPrice;
/** 商品税额 */
private BigDecimal itemTax;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public boolean getImported() {
return imported;
}
public void setImported(boolean imported) {
this.imported = imported;
}
public BigDecimal getItemPrice() {
return itemPrice;
}
public void setItemPrice(BigDecimal itemPrice) {
this.itemPrice = itemPrice;
}
public BigDecimal getItemTax() {
return itemTax;
}
public void setItemTax(BigDecimal itemTax) {
this.itemTax = itemTax;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public BigDecimal getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(BigDecimal unitPrice) {
this.unitPrice = unitPrice;
}
public void reset(){
this.name = "";
this.count = 0;
this.unitPrice = BigDecimal.ZERO;
this.type = "";
this.imported = false;
this.itemPrice = BigDecimal.ZERO;
this.itemTax = BigDecimal.ZERO;
}
@Override
public String toString(){
String strForm = "";
strForm += "ProductForm=[\r\n";
strForm += "this.name=" +this.name + "\r\n";
strForm += "this.count=" +this.count + "\r\n";
strForm += "this.unitPrice=" +this.unitPrice.toString() + "\r\n";
strForm += "this.type=" +this.type + "\r\n";
strForm += "this.imported=" +this.imported + "\r\n";
strForm += "this.itemPrice=" +this.itemPrice.toString() + "\r\n";
strForm += "this.itemTax=" +this.itemTax.toString() + "\r\n";
strForm += "]";
return strForm;
}
}
ProductResultForm.java:
package com.xy6.interview;
import java.math.BigDecimal;
/**
* 购物车表单类
*
* @author daxiang
* @since 2014-07-17
*/
public class ProductResultForm {
public ProductResultForm(){
this.bdTotalPrice = BigDecimal.ZERO;
this.bdTotalTax = BigDecimal.ZERO;
}
/** 商品总价 */
private BigDecimal bdTotalPrice;
/** 商品税额 */
private BigDecimal bdTotalTax;
public BigDecimal getBdTotalPrice() {
return bdTotalPrice;
}
public void setBdTotalPrice(BigDecimal bdTotalPrice) {
this.bdTotalPrice = bdTotalPrice;
}
public BigDecimal getBdTotalTax() {
return bdTotalTax;
}
public void setBdTotalTax(BigDecimal bdTotalTax) {
this.bdTotalTax = bdTotalTax;
}
@Override
public String toString(){
String strForm = "";
strForm += "ProductResultForm=[\r\n";
strForm += "this.bdTotalPrice=" +this.bdTotalPrice.toString() + "\r\n";
strForm += "this.bdTotalTax=" +this.bdTotalTax.toString() + "\r\n";
strForm += "]";
return strForm;
}
}