数组——购物系统中的

来源:互联网 发布:java 尚学堂300 编辑:程序博客网 时间:2024/06/03 21:08
import java.util.Scanner;import java.util.Random;/** *@author:岳丽萍 *@date:2014.4.5 *@team:购物管理系统 */ public class Shopping{ public static void main(String [] args){         //显示首页  int loginIndex = 0;//登录失败的次数 xun1: while(true){  System.out.println("\t\t我行我素购物管理系统");    System.out.println("**************************");    System.out.println("\t\t1.登录系统");    System.out.println("\t\t2.更改管理员密码");    System.out.println("\t\t3.退出");        System.out.println("**************************");xun2:while(true){                System.out.print("请输入您的选项:");    Scanner  input = new Scanner(System.in);        int choice = input.nextInt();    //选择登录系统xun3:while(true){if(choice == 1){System.out.print("请输入用户名:");String usename = input.next();System.out.print("请输入密码:");String password = input.next();if("admin".equals(usename)&&"admin".equals(password)){System.out.println("登陆成功!");        //进入第二个菜单 登录系统        xun4:while(true){System.out.println("\t\t欢迎使用我行我素购物管理系统");System.out.println("**************************************************");System.out.println("\t\t1.客户信息管理");System.out.println("\t\t2.购物结算");System.out.println("\t\t3.真情回馈");System.out.println("\t\t4.返回上一级");System.out.println("**************************************************");xun5:    while(true){System.out.print("请输入您的选择:");                                    int choice1 = input.nextInt();            //第三层菜单            switch(choice1){//客户管理系统case 1:xun6:while(true){                                                System.out.println("我行我素客户管理系统 > 客户信息管理");System.out.println("*****************************************************");System.out.println("\t\t1.显示所有客户信息");System.out.println("\t\t2.添加客户信息");System.out.println("\t\t3.修改客户信息");System.out.println("\t\t4.查询客户信息");System.out.println("\t\t5.返回上一级");System.out.println("*****************************************************");System.out.print("请输入您的选择:");int choice2 = input.nextInt();switch(choice2){//显示所有客户信息case 1:String [] custom = new String[100];custom[0] ="1001\t\t小猫\t\t1992-7-10\t\t20000";custom[1] ="1001\t\t小狗\t\t1992-6-17\t\t25000";custom[2] ="1001\t\t小马\t\t1992-7-10\t\t30000";custom[3] ="1001\t\t小狐狸\t\t1992-11-1\t\t10000";custom[4] ="1001\t\t大象\t\t1992-11-17\t\t10000";for(int i = 0; i < 100;i ++){                                                            System.out.println(custom [i]);}System.out.println("请按任意键结束!");String renyi = input.next();                                                         if(renyi != "\r"){ continue; }            System.exit(1);                // 添加客户信息                                                    case 2:System.out.println("欢迎添加客户!");System.out.println("请输入新的客户名称<2-8个字符>:");String name = input.next();System.out.println("请输入新客户的生日格式:<yyyy-MM-dd>:");String birthday = input.next();System.out.println("请输入新客户的积分:");int integral = input.nextInt();//积分System.out.println("恭喜客户添加成功!");System.out.println("请按任意键继续!");String renyi1 = input.next();                                                          if(renyi1 != "\r"){ continue; }//不足System.exit(1);//修改客户信息case 3:System.out.println("系统缺陷");                System.exit(1);            break;                //查询客户信息case 4:System.out.print("请输入您要查询的客户编号:");            int choice4 = input.nextInt();            switch(choice4){case 1001:System.out.println("1001\t\t小猫\t\t1992-7-10\t\t20000");break;case 1002:System.out.println("1002\t\t小狗\t\t1992-6-17\t\t25000");break;case 1003:System.out.println("1003\t\t小马\t\t1992-7-10\t\t30000");break;case 1004:System.out.println("1004\t\t小狐狸\t\t1992-11-1\t\t10000");break;case 1005:System.out.println("1005\t\t大象\t\t1992-11-17\t\t10000");break;default :System.out.println("没有这个用户!");}System.out.println("请按任意键结束!");String renyi2 = input.next();                                                          if(renyi2 != "\r"){                                                               continue;                                                         }             System.exit(1);case 5:break xun5;default:System.out.println("您的输入有误!");continue;}    }//xun6:                                        //购物结算case 2:xun7:while(true){System.out.println("欢迎进入购物系统!");System.out.println("请输入您的客户编号:");int shopnum = input.nextInt();//客户名称if(shopnum == 1001||shopnum == 1002||shopnum == 1003||shopnum == 1004||shopnum == 1005){System.out.println("商城现有如下商品:");System.out.println("商品编号\t\t商品名称\t\t商品价格");System.out.println("1\t\t云南白药\t\t¥18.00");System.out.println("2\t\t小米手机\t\t¥1,999.00");System.out.println("3\t\t小黑  \t\t¥4,998.00");System.out.println("4\t\t拖鞋  \t\t¥25.80");System.out.println("5\t\t酱油  \t\t¥5.6");System.out.println("6\t\t汽车模型\t\t¥350.00");System.out.println("7\t\t坦克模型\t\t¥400.00");System.out.println("8\t\t玩具枪 \t\t¥99.80");xun8:while(true){System.out.print("请输入您要的编号:");int x = input.nextInt();//x表示要购买商品的编号System.out.println("请输入您要购买的产品数量:");int count = input.nextInt();                                double a = 0;    String b = null;switch(x){case 1:    b = "云南白药";        a = 18.00;System.out.println("云南白药");    break;    case 2:                                    b = "小米手机";    a = 1998.00;System.out.println("小米手机");break;case 3:b = "小黑";    a = 4998.00;System.out.println("小黑");break;case 4:b = "拖鞋";    a = 25.80;System.out.println("拖鞋");break;case 5:b = "酱油";    a = 5.60;System.out.println("酱油");break;case 6:                                    b = "汽车模型";    a = 350.00;System.out.println("汽车模型");break;case 7:b = "坦克模型";    a = 400.00;System.out.println("坦克模型");break;case 8:b = "玩具枪";    a = 99.80;System.out.println("玩具枪");break;default :System.out.println("您的输入有误");    break;}//继续购买System.out.println("是否继续购买?<输入y继续购买>");String shifou = input.next();if("y".equals(shifou)){count = + count;continue;}else{                                        //不继续购物,付款double money =(double) a * count * 0.85;System.out.println("尊敬的用户:" + shopnum);//打印用户名称System.out.println("产品名称\t\t产品单价\t\t购买数量\t\t产品总价");System.out.println(b+"\t\t"+a+"\t\t"+count+"\t\t"+money);//打印要购买的商品以及价格System.out.println("您购买的商品总价为:¥" + a*count);System.out.println("按您当前的积分,您享受的折扣是:0.85");System.out.println("您的应付款为:" + money);xun9:while(true){System.out.print("请付款:");int pay = input.nextInt();if(pay >= money) {System.out.println("付款成功!");System.out.println("找零:" + (pay - money));System.out.println("欢迎下次光临!");System.out.println("请按任意键继续!");System.exit(1);}else{System.out.println("对不起,您的金额不足,请重新付款:");    continue ;//}}//xun9:}}//xun8:}}case 3:xun10:while(true){System.out.println("我行我素购物管理系统 > 真情回馈");System.out.println("****************************************************");System.out.println("\t\t1.幸运大放送");System.out.println("\t\t2.幸运抽奖");System.out.println("\t\t3.生日问候");System.out.println("\t\t4.返回上一级");System.out.println("****************************************************");System.out.println("请输入您的选择:");int choice3 = input.nextInt();switch(choice3){//幸运大放送case 1: System.out.println("积分最高的客户是:"); System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分"); System.out.println("1001\t\t小猫\t\t1992-7-10\t\t46211"); System.out.println("恭喜以上用户,获得一个价值¥13.50的黑人牙膏"); System.out.println("请按任意键继续!");                                                     String renyi = input.next();                                                      if(renyi != "\r"){ continue; }case 2:Random rand = new Random();                                    int randNum = (Math.abs((new Random().nextInt())))%5 + 1004;switch(randNum){case 1001:System.out.println("幸运客户是:");    System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");System.out.println("1001\t\t小猫\t\t1992-7-10\t\t46211");System.out.println("恭喜以上用户,获得一个价值¥13.50的黑人牙膏");System.out.println("请按任意键继续!");String renyi3 = input.next();                                                      if(renyi3 != "\r"){ continue;}case 1002:System.out.println("幸运客户是:");    System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");System.out.println("1002\t\t小狗\t\t1992-6-17\t\t25000");System.out.println("恭喜以上用户,获得一个价值¥3.50的大枣");System.out.println("请按任意键继续!");String renyi4 = input.next();                                                      if(renyi4 != "\r"){ continue;}case 1003:System.out.println("幸运客户是:");    System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");System.out.println("1003\t\t小马\t\t1992-7-10\t\t30000");System.out.println("恭喜以上用户,获得一个价值¥999.00的洗衣机");System.out.println("请按任意键继续!");String renyi8 = input.next();                                                      if(renyi8 != "\r"){ continue;}case 1004:System.out.println("幸运客户是:");    System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");System.out.println("1004\t\t小狐狸\t\t1992-11-1\t\t10000");System.out.println("恭喜以上用户,获得一个价值¥88.00的剃须刀");System.out.println("请按任意键继续!");String renyi9 = input.next();                                                      if(renyi9 != "\r"){ continue;}case 1005:System.out.println("幸运客户是:");    System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");System.out.println("10051\t\t大象\t\t1992-11-17\t\t10000");System.out.println("恭喜以上用户,获得一个价值¥50.00的话费充值卡");System.out.println("请按任意键继续!");String renyi5 = input.next();                                                      if(renyi5 != "\r"){ continue;}}//生日问候case 3:System.out.println("对不起今天没有过生日的用户!");System.out.println("请按任意键继续!");String renyi6 = input.next();  if(renyi6 != "\r"){  continue;}//返回上一级case 4: break xun5;default:System.out.println("您的输入有误!");    System.exit(1);}}//xun10://返回上一级case 4:break xun2;default:System.out.println("您的输入有误!");break;}        }//xun5:}//xun4:}}if(choice == 2){System.out.print("请输入用户名:");String usename = input.next();System.out.print("请输入密码:");String password = input.next();System.out.println("请输入新密码:");String newpassword =input.next();System.out.println("请确认新密码:");System.out.println("恭喜您,密码修改成功!");System.out.println("请按任意键继续!");String renyi7 = input.next();  if(renyi7 != "\r"){ continue;}//continue ;}else if(choice == 3){System.exit(1);}else{System.out.println("您的输入有误!");        break;}}//xun3}//xun2 }//sun1: } }

0 0
原创粉丝点击