import java.util.Scanner;
class method1{
//模拟超市购物,代码重构
//用户选择1.购买商品,2.结账(打印小票),3.取消购买,
//键盘录入 ,,重置数量的方法,流水查询,总账查询
//创建一个数组,定义一个变量记录索引
//定义少林寺酥饼核桃的属性成员变量
static String slId = "( 090115 )";
static String slName = "少林寺酥饼核桃";
static double slqj = 15.50;
static String slge = "个";
static double slNumber = 0.0;
static double slMoney = 0.0;
//然光Q移属性
static String rgId = ("( 090028 )");
static String rgName = ("然光Q移");
static double rgqj = 16.00;
static String rgge = "个";
static double rgNumber = 0.0;
static double rgMoney = 0.0;
//北京尚康杂粮牡丹饼属性
static String skId = ("( 090027 )");
static String skName = ("北京尚康杂粮牡丹饼");
static double skqj =14.50;
static String skge = "个";
static double skNumber = 0.0;
static double skMoney = 0.0;
static double[] arr = new double[77];
static int index = 0;
public static void main(String[] args){
while(true){
System.out.println(" 欢 迎 光 临 ");
System.out.println(" 1: 购买商品 2: 结账 3:流水查询 4:总账查询 5: 取消购买");
int x = cblr();
switch(x){
case 1://购买
buy();
break;
case 2: //结账//打印消费信息
pay();
czNumber();
break;
case 3:
break;
case 4:
break;
case 5:
qxNumber();
czNumber();
break;
default:
System.out.println("你的输入有误!");
break;
}
}
}
//购买方法
public static void buy(){
System.out.println(" 欢 迎 光 临 ");
System.out.println(" 编号 品名 售价 计价单位");
System.out.println(slId+slName+" "+slqj+" "+slge);
System.out.println(rgId+rgName+" "+rgqj+" "+rgge);
System.out.println(skId+rgName+" "+skqj+" "+skge);
System.out.println("请输入你要购买少林寺酥饼核桃的件数:");
slNumber = cblr();
System.out.println("请输入你要购买然光Q移的件数:");
rgNumber = cblr();
System.out.println("请输入你要购买北京尚康杂粮牡丹饼件数:");
skNumber = cblr();
}
//结账方法
public static void pay(){
if(slName.length() > 7){
slName = slName.substring(0,7)+"...";
}
if(rgName.length() > 7){
rgName = rgName.substring(0,7)+"...";
}
if(slName.length() > 7){
skName = skName.substring(0,7)+"...";
}
slMoney = slNumber*slqj;
System.out.println("购买了:"+slName+slNumber+"件 总价:"+slMoney);
rgMoney = rgNumber*rgqj;
System.out.println("购买了:"+rgName+rgNumber+"件 总价:"+rgMoney);
skMoney = skNumber*skqj;
System.out.println("购买了:"+skName+skNumber+"件 总价:"+skMoney);
//总个数总价
double sumNumber = slNumber+slNumber+rgNumber;
double sumMoney = slMoney+rgMoney+skMoney;
//判断消费是否1000元是否购买少林寺酥饼核桃30个,是打九折,
slMoney = (slNumber >=30) &&(slMoney >=1000) ? slMoney*0.9 :slMoney;
if (sumMoney >= 1000 && slNumber >= 50){
double sumMoney1 = sumMoney*0.75;
}
if(sumMoney >= 300 && sumMoney < 600){
double sumMoney1 = sumMoney*0.95;
}else if(sumMoney >= 600 && sumMoney < 900){
double sumMoney1 = sumMoney*0.85;
}else if(sumMoney >= 1000 ){
double sumMoney1 = sumMoney*0.8;
}
//用数学工具类的round方法四舍五入
long sumMoney1 = (long)Math.round(sumMoney);
//付账找零
long fzMoney = 10000000000L;
long zlMoney = fzMoney - sumMoney1;
System.out.println(" 您购买了:"+sumNumber+"件商品");
System.out.println(" 总计: "+sumMoney1+"元 实付: "+fzMoney+" 找零: "+zlMoney);
System.out.println(" 2016.03.17-0001-001-777 19:45:22");
System.out.println(" 凭此小票换取发票!");
czNumber();
}
//取消购买
public static void qxNumber(){
System.out.println("爱买不买,不买拉倒!");
}
//重置数量
public static void czNumber(){
slNumber = 0.0;
slqj = 0.0;
rgNumber = 0.0;
rgqj = 0.0;
skNumber = 0.0;
skqj = 0.0;
}
//键盘录入 ,
public static int cblr(){
Scanner sc = new Scanner(System.in);
int c = sc.nextInt();
return c;
}
}
|
|