1 public static void shoppingSettlementPage(int salesManSid) { 2 System.out.println("■■■■■■■■■■■■■■■■结算■■■■■■■■■■■■■■■■"); 3 do { 4 System.out.println("按 S 开始购物结算.按 0 返回账户登录界面"); 5 String choiNext=ScannerInfoString(); 6 if("0".equals(choiNext)){ 7 //上一页 8 checkstandLogPage(); 9 }else if ("s".equals(choiNext) || "S".equals(choiNext)) { 10 System.out.println("\n--请输入商品编号或商品名--"); 11 int gid=QueryPrint.querySettlement(); 12 switch (gid) { 13 case -3: 14 break; 15 case -1: 16 System.out.println("售罄!"); 17 break; 18 default: 19 System.out.println("商品编号:"); 20 int shoppingGid=ScannerNum(); 21 ArrayList<Goods> goodsList=new QueryPrint().queryGoodsKey(shoppingGid, null); 22 if(goodsList==null || goodsList.size()==0){ 23 System.out.println("未查询到该商品!"); 24 }else { 25 Goods goods=goodsList.get(0); 26 int gNum=goods.getGnum(); 27 double gPrice=goods.getGprice(); 28 System.out.println("请输入购买数量:"); 29 do { 30 int choicegoodsNum=ScannerNum(); 31 if(choicegoodsNum>gNum){ 32 System.err.println("\t!!仓库储备不足!!"); 33 System.out.println("--请重新输入购买数量--"); 34 }else { 35 double allPrice=Arith.mul(choicegoodsNum, gPrice); 36 System.out.println("\t\t\t 购物车结算\n"); 37 System.out.println("\t\t商品名称\t商品单价\t购买数量\t总价\n"); 38 System.out.println("\t\t" + goods.getGname()+ "\t" + gPrice + " $\t"+ choicegoodsNum + "\t" + allPrice 39 + " $\n"); 40 41 do { 42 System.out.println("确认购买:Y/N"); 43 String chshopping=ScannerInfoString(); 44 if ("Y".equals(chshopping) ||"y".equals(chshopping)) { 45 System.out.println("\n总价:" + allPrice 46 + " $"); 47 System.out.println("\n实际缴费金额"); 48 49 do { 50 double amount=ScannerInfo(); 51 double balance=Arith.sub(amount, allPrice); 52 if(balance<0){ 53 System.err.println("\t!!缴纳金额不足!!"); 54 System.out.println("\n请重新输入缴纳金额($)"); 55 }else { 56 Gsales gSales = new Gsales(goods.getGid(),salesManSid,choicegoodsNum); 57 boolean insert=new GsalesDao().shoppingSettlement(gSales); 58 int goodsNewNum=gNum-choicegoodsNum; 59 Goods newGoods=new Goods(goods.getGid(),goodsNewNum); 60 boolean update = new GoodsDao().updateGoods(3, newGoods); 61 if(update && insert){ 62 System.out.println("找零:"+ balance); 63 System.out.println("\n谢谢光临,欢迎下次惠顾"); 64 }else { 65 System.out.println("!支付失败!"); 66 } 67 shoppingSettlementPage(salesManSid); 68 } 69 } while (true); 70 }else if ("n".equals(chshopping) || "N".equals(chshopping)) { 71 shoppingSettlementPage(salesManSid); 72 } 73 System.out.println("确定购买?"); 74 } while (true); 75 } 76 } while (true); 77 } 78 break; 79 } 80 }else { 81 System.out.println("输入有误!"); 82 } 83 } while (true); 84 }
1 public static int querySettlement() { 2 int gid=-1; 3 ArrayList<Goods> goodsSetList=new GoodsDao().queryGoods(3); 4 if(goodsSetList==null || goodsSetList.size()<=0){ 5 System.out.println("无此商品!"); 6 gid=-3; 7 }else { 8 System.out.println("\t\t\t\t\t商品列表\n\n"); 9 System.out.println("\t商品编号\t\t商品名称\t\t商品价格\t\t商品数量\t\t备注\n"); 10 11 for (int i = 0; i < goodsSetList.size(); i++) { 12 Goods goods=goodsSetList.get(i); 13 if(goods.getGnum()>0){ 14 System.out.print("\t" + goods.getGid() + "\t\t" 15 + goods.getGname() + "\t\t" + goods.getGprice() 16 + "\t\t" + goods.getGnum()); 17 18 if(goods.getGnum()==0){ 19 System.out.println("售罄"); 20 }else if (goods.getGnum()<10) { 21 System.out.println("即将售完(低于十件)"); 22 }else { 23 System.out.println(); 24 } 25 if(goodsSetList.size()== 1){ 26 gid=goods.getGid(); 27 }else { 28 gid=-2; 29 } 30 } 31 } 32 } 33 return gid; 34 }
1 package per.sww.tools; 2 3 import java.math.BigDecimal; 4 5 public class Arith { 6 private static final int DEE_DIV_SCALE=2; 7 8 public Arith() { 9 } 10 11 public static double add(double v1,double v2){ 12 BigDecimal b1=new BigDecimal(Double.toString(v1)); 13 BigDecimal b2=new BigDecimal(Double.toString(v2)); 14 return b1.add(b2).doubleValue(); 15 } 16 17 public static double mul(double v1,double v2) { 18 BigDecimal b1=new BigDecimal(Double.toString(v1)); 19 BigDecimal b2=new BigDecimal(Double.toString(v2)); 20 return b1.add(b2).doubleValue(); 21 } 22 23 public static double sub(double v1,double v2) { 24 BigDecimal b1=new BigDecimal(Double.toString(v1)); 25 BigDecimal b2=new BigDecimal(Double.toString(v2)); 26 return b1.subtract(b2).doubleValue(); 27 } 28 29 public static double div(double v1,double v2){ 30 return div(v1, v2); 31 } 32 33 34 public static double div(double v1,double v2,int scale){ 35 if(scale<0){ 36 throw new IllegalArgumentException("The scale must be a positive integer or zero"); 37 } 38 BigDecimal b1=new BigDecimal(Double.toString(v1)); 39 BigDecimal b2=new BigDecimal(Double.toString(v2)); 40 return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); 41 } 42 43 public static double round(double v,int scale){ 44 if(scale<0){ 45 throw new IllegalArgumentException("The scale must be a positive integer or zero"); 46 } 47 48 BigDecimal bigDecimal=new BigDecimal(Double.toString(v)); 49 BigDecimal one=new BigDecimal("1"); 50 return bigDecimal.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); 51 } 52 }
public static double mul(double v1,double v2) { BigDecimal b1=new BigDecimal(Double.toString(v1)); BigDecimal b2=new BigDecimal(Double.toString(v2)); return b1.multiply(b2).doubleValue(); }
這個寫錯..你寫成"加"了
那个改回来了还是这样子= =
@眉间剪水泛千愁:
怎麼可能?!
@RosonJ: 真的