@@ -0,0 +1,2396 @@
+package org.qpt.receipt;%0A%0Aimport org.qpt.util.JsonDataParser;%0A%0Aimport java.io.IOException;%0Aimport java.util.Hashtable;%0Aimport java.util.List;%0A%0A/**%0A * Created by JonirRings on 2016/7/6.%0A */%0Apublic class Cart %7B%0A    Hashtable%3CString, Goods%3E goodInfoTable = new Hashtable%3C%3E();%0A    Hashtable%3CString, Item%3E itemTable = new Hashtable%3C%3E();%0A%0A    public Cart() throws IOException %7B%0A        List%3CGoods%3E list = JsonDataParser.ReadGoodsFromStream(Cart.class.getClassLoader().getResourceAsStream(%22goods.json%22));%0A        for (Goods good :%0A                list) %7B%0A            goodInfoTable.put(good.getBarcode(), good);%0A        %7D%0A    %7D%0A%0A    public int AddGoods(String mixedCode) %7B%0A        String%5B%5D strs = mixedCode.split(%22-%22);%0A        if (strs.length %3C 2) %7B%0A            throw new IllegalArgumentException(%22expect a string with %5C%22-%5C%22!%22);%0A        %7D%0A        return AddGoods(strs%5B0%5D, Integer.parseInt(strs%5B1%5D));%0A    %7D%0A%0A    public int AddGoods(String barcode, int quantity) throws IllegalArgumentException %7B%0A        if (itemTable.isEmpty() %7C%7C !itemTable.containsKey(barcode)) %7B%0A            Goods goods = goodInfoTable.get(barcode);%0A            if (goods != null) %7B%0A                itemTable.put(barcode, new Item(goodInfoTable.get(barcode), quantity));%0A                return quantity;%0A            %7D%0A            throw new IllegalArgumentException(%22the barcode %22 + barcode + %22 does not match any goods%22);%0A        %7D%0A        Item item = itemTable.get(barcode);%0A        item.setQuantity(item.getQuantity() + quantity);%0A        return item.getQuantity();%0A    %7D%0A%0A    public int ReduceGoods(String barcode, int quantity) throws IllegalArgumentException %7B%0A        if (itemTable.isEmpty() %7C%7C !itemTable.containsKey(barcode)) %7B%0A            throw new IllegalArgumentException(%22the barcode %22 + barcode + %22 does not match any goods%22);%0A        %7D%0A        Item item = itemTable.get(barcode);%0A        item.setQuantity(item.getQuantity() + quantity);%0A        int retQuantity = item.getQuantity();%0A        if (item.getQuantity() %3C= 0)%0A            itemTable.remove(barcode);%0A        return retQuantity;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        StringBuilder sb = new StringBuilder();%0A        for (Item item :%0A                itemTable.values()) %7B%0A            sb.append(item.getGoods().getBarcode()).append(%22-%22).append(item.getQuantity()).append(System.lineSeparator());%0A        %7D%0A        return sb.toString();%0A    %7D%0A%7D%0A

implement basic Cart class