购物系统项目

来源:互联网 发布:百度网站怎么优化 编辑:程序博客网 时间:2024/05/17 22:27
/****/import java.util.Scanner;//导入一个外部的java类import java.text.SimpleDateFormat;import java.util.Scanner;//导入一个有关日期的java类public class Login {public static void main(String [] args) {String username0 = "admin";String password0 = "1111";//定义变量存放默认的用户名和密码int loginIndex = 0;//定义一个变量,存放用户登录的次数      String [] name = new String[10];//定义存放10个客户姓名的数组变量        name[0] = "小猫"; name[1] = "小狗";name[2] = "小马";name[3] = "小狐狸";name[4] = "大象";int [] number = new int[10];//定义一个存放10个客户编号的数组变量number[0] = 1001;number[1] = 1002;number[2] = 1003;number[3] = 1004;number[4] = 1005;String [] birthday = new String[10];//定义一个存放10个客户出生年月日的数组变量        birthday[0] = "1992-07-10";        birthday[1] = "1992-06-17";        birthday[2] = "1992-07-10";birthday[3] = "1992-11-01";birthday[4] = "1992-11-17";String [] date = new String[5];//定义一个存放客户生日的数组变量date[0] = "07-10";date[1] = "06-17";date[2] = "07-10";date[3] = "11-01";date[4] = "11-17";       int [] num = new int[10];//定义一个存放10个客户积分的数组变量        num[0] = 20000;        num[1] = 25000;num[2] = 30000;num[3] = 10000;        num[4] = 10000;first:while(true) {//用于返回上一级//展示登录菜单    System.out.println("\t\t\t欢迎使用我行我素购物管理系统1.0版");    System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");    System.out.println("\t\t\t1.登录系统");    System.out.println("\t\t\t2.更改管理员密码");    System.out.println("\t\t\t3.退出");            System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");    //提示用户输入选项    System.out.print("请输入您的选择:");    Scanner input = new Scanner(System.in);second:    while(true){//输入上面选项的循环        int choice1 = input.nextInt();        //判断用户输入选项是否正确        if(choice1 == 1) {/*登录系统*/                    /*用户输入登录,如果登录失败,继续重新登录,失败次数超过三次,退出系统*/third:while(true) {    //登录系统要实现的功能:提示用户输入用户名和密码        System.out.println("请输入用户名:");    String username = input.next();    System.out.println("请输入密码:");    String password = input.next();    //判断用户输入的用户名是否admin,密码是否1111    /*整数判断可以用==;字符串是否相等用equals*/                        if((username0).equals(username)&&(password0).equals(password)) {System.out.println("登录成功!");break;//退出循环    } else {    loginIndex ++;                            if(loginIndex > 2) {System.out.println("输入次数超过三次;系统即将退出...");System.exit(1);}                            System.out.println("您输入的用户名和密码错误,您还有" + (3 - loginIndex) + "次机会重新输入");} }//登录成功fourth:while(true){                  System.out.println("\t\t\t欢迎使用我行我素购物管理系统");    System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");    System.out.println("\t\t\t1.客户信息管理");    System.out.println("\t\t\t2.购物结算");    System.out.println("\t\t\t3.真情回馈");    System.out.println("\t\t\t4.返回上一级");                        System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");    System.out.println("请输入您的选择:");                        fifth:    while(true) {//对用户输入的选项的判断        int choice2 = input.nextInt();                                          if(choice2 == 1) {//客户信息管理sixth:while(true) {int choice3;System.out.println("我行我素购物管理系统 > 客户信息管理");System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");System.out.println("\t\t\t1.显示所有客户信息");System.out.println("\t\t\t2.添加客户信息");System.out.println("\t\t\t3.修改客户信息");System.out.println("\t\t\t4.查询客户信息");                                    System.out.println("\t\t\t5.返回上一级");                                    System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");System.out.println("请输入您的选择:");                                    seventh:    while(true) {//对输入选项的判断        choice3 = input.nextInt();        if(choice3 == 1) {//显示所有客户信息        System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");       for(int i = 0;i <= name.length;i++) {    System.out.println(number[i] + "\t\t" + name[i] + "\t\t" + birthday[i] + "\t\t" + num[i]);    }break;        } else if(choice3 == 2) {//添加客户信息         System.out.println("欢迎添加客户!");    System.out.println("请输入新客户的名称(2-8个字符):");        String newname = input.next();    System.out.println("请输入新客户的生日(格式:yyyy-mm-dd):");    String newbirthday = input.next();System.out.println("请输入新客户的积分:");int newnum = input.nextInt();System.out.println("添加成功!");break fifth;        } else if(choice3 == 3) {//修改客户信息System.out.println("请输入你要修改的客户编号:");                                            int number0 = input.nextInt();for(int k = 1;k <= number.length;k++){if(number0 == number[k]){                                                     System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");             System.out.println(number[k] + "\t\t" + name[k] + "\t\t" + birthday[k] + "\t\t" + num[k]);}                                                System.out.println("请选择你要修改的内容:1.姓名\t\t2.生日");System.out.println("请输入你的选择:");                                                int choose = input.nextInt();if(choose == 1){System.out.println("请输入新的客户名称:");                                                    String newname0 = input.next();System.out.println("修改成功");}else if(choose == 2){System.out.println("请输入新的客户生日:");String newbirthday0 = input.next();System.out.println("修改成功");}}        break fifth;        } else if(choice3 == 4) {//查询客户信息                                            System.out.println("请输入你要查询的客户编号:");                                            int number1 = input.nextInt();for(int j = 1;j <= number.length;j++){if(number1 == number[j]){                                                     System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");             System.out.println(number[j] + "\t\t" + name[j] + "\t\t" + birthday[j] + "\t\t" + num[j]);}else{System.out.println("你要查询的客户编号不存在:");}break;}           break;        } else if(choice3 == 5) {        //返回上一级break fifth;        } else {    System.out.println("输入有误,请重新输入!");    }    }//循环结束if(choice3 != 5) {                                        System.out.println("请输入任意键继续:");break ;}        }//循环结束break fifth;        } else if(choice2 == 2) {//购物结算    System.out.println("欢迎进入购物系统!");    System.out.println("请输入您的客户编号:");String name1 = null;int y = 0;while(true){                                    y = 0;        int number1 = input.nextInt();    while(true){    if(number1 == number[y]) {    name1 = name[y];    break;    }    y++;    if(y > number.length){    System.out.println("您输入的标号错误,请重新输入!");    break;    }    }if(y <= number.length){break;}}                                System.out.println("商城现有商品如下:");        System.out.println("商品编号\t\t商品名称\t\t商品价格");        System.out.println("1\t\t\t云南白药\t\t¥18.00");        System.out.println("2\t\t\t小米手机\t\t¥1,998.00");        System.out.println("3\t\t\t小黑\t\t\t¥4,998.00");                                System.out.println("4\t\t\t拖鞋\t\t\t¥25.80");                                System.out.println("5\t\t\t酱油\t\t\t¥5.60");        System.out.println("6\t\t\t汽车模型\t\t¥350.00");        System.out.println("7\t\t\t坦克模型\t\t¥400.00");        System.out.println("8\t\t\t玩具枪\t\t¥99.80");                                System.out.print("请输入您要购买的产品编号:");        int choice4 = input.nextInt();        System.out.print("请输入您要购买的产品数量:");        int choice5 = input.nextInt();        double sum = 0;        double a = 0;        String str = null;        switch (choice4) {case 1:            sum = choice5 * 18;                a = 18;                str = "云南白药";                                        break;            case 2:            sum = choice5 * 1998;                a = 1998;                str = "小米手机";                break;            case 3:            sum = choice5 * 4998;                a = 4998;                str = "小黑";                break;            case 4:            sum = choice5 * 25.8;                a = 25.8;                str = "拖鞋";                break;            case 5:            sum = choice5 * 5.6;                a = 5.6;                str = "酱油";                break;            case 6:            sum = choice5 * 350;                a = 350;                str = "汽车模型";                break;            case 7:            sum = choice5 * 400;                a = 400;                str = "坦克模型";                break;            case 8:            sum = choice5 * 99.8;                a = 99.8;                str = "玩具枪";                break;            default:            break;        }                System.out.println("尊敬的用户:" + name1);        System.out.println("产品名称\t\t产品单价\t\t购买数量");        System.out.println(str + "\t\t" + a +"\t\t\t" + choice5);        System.out.println("您购买的产品总价为:¥" + sum);        System.out.println("按您当前的积分,您的折扣是:0.85");                    double b;                b = 0.85 * sum;                System.out.println("您的应付款为:¥" + (float)b);System.out.print("请付款:");            while(true) {//付款成功的循环                                    int x = input.nextInt();                                    if(x < sum){            System.out.println("付款错误,请重新付款!");            } else {            System.out.println("付款成功!");            System.out.println("找零:¥" + (float)(x - b));            System.out.println("欢迎下次光临!");    break;            }    }//循环结束System.out.println("请按任意键继续:");String str2 = input.next();    break fifth;        } else if(choice2 == 3) {/*真情回馈*/                                one:while(true) {int choice6;System.out.println("我行我素购物管理系统 > 真情回馈");System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");System.out.println("\t\t\t1.幸运大放送");System.out.println("\t\t\t2.幸运抽奖");System.out.println("\t\t\t3.生日问候");                                    System.out.println("\t\t\t4.返回上一级");                                    System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");System.out.println("请输入您的选择:");                                    two:    while(true) {//对输入选项的判断        choice6 = input.nextInt();        if(choice6 == 1) {//幸运大放送   System.out.println("获得最高积分的客户是:");       System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");   System.out.println(number[2] + "\t\t" + name[2] + "\t\t" + birthday[2] + "\t\t" + num[2]);   System.out.println("恭喜以上用户,获得一个价值¥50.00的充值卡");                                           System.out.println("请按任意键继续:");       }else if(choice6 ==2 ){//幸运抽奖   System.out.println("幸运客户是:");       System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");   System.out.println(number[2] + "\t\t" + name[2] + "\t\t" + birthday[2] + "\t\t" + num[2]);   System.out.println("恭喜以上用户,获得一个价值¥5,888,00的Iphone5s");                                           System.out.println("请按任意键继续:");           }else if(choice6 == 3){//生日问候                                        String today = "04-09";    for(int m = 0;m < birthday.length;m++){   if((today).equals(date[m])){                                                System.out.println("尊敬的客户,生日快乐!:");                                                System.out.println("恭喜你获得生日贺卡!:");   }   else{   System.out.println("对不起,今天没有过生日的客户!:");   }   System.out.println("请按任意键继续!");   break ;   }                                                    }else if(choice6 == 4){//返回上一级   break fifth;          }else{//提示输入错误,重新输入   System.out.println("输入错误,请重新输入");   break;       }       }if(choice6 != 4) {                                        System.out.println("请输入任意键继续:");continue  ;}}} else if(choice2 == 4) {//返回上一级break second;        } else{//提示输入错误,重新输入System.out.println("输入错误,请重新输入");break;        }}    }//输入选项的循环        } else if(choice1 == 2) {/*更改管理员密码*/while(true) {System.out.println("请输入用户名:");String usename = input.next();System.out.println("请输入密码:");String password = input.next();            if((username0).equals(usename)&&(password0).equals(password)) {System.out.println("请输入新密码:");String newname = input.next();System.out.println("请确认新密码:");String newpass = input.next();   if(newname.equals(newpass)){   System.out.println("恭喜你,修改密码成功!");   System.out.println("按任意键继续");   }     } else {    loginIndex ++;                            if(loginIndex > 2) {System.out.println("输入次数超过三次;系统即将退出...");System.exit(1);}                            System.out.println("您输入的用户名和密码错误,您还有" + (3 - loginIndex) + "次机会重新输入");} break second;}//修改密码成功         } else if(choice1 == 3) {/*退出系统*/    System.out.println("系统即将退出....");System.exit(1);        } else {/*提示用户输入错误,请重新输入*/            System.out.println("输入有误,请重新输入:");        }        }//输入选项的循环        }//登录菜单}}

0 0
原创粉丝点击