购物管理系统

来源:互联网 发布:有限元分析软件pfepg 编辑:程序博客网 时间:2024/06/08 17:19
package oracle;import java.util.Scanner;/* * 显示菜单类 * firstMenu()  显示主菜单 * loginMenu()显示管理菜单 * guestManage() 显示客户信息菜单 * repairMessage() 显示修改菜单 * feedBack()   显示幸运菜单 */class showMenu{void firstMenu(){System.out.println("欢迎使用我行我素购物管理系统7.3版");System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");System.out.println("1. 登 录 系 统\n");System.out.println("2. 更 改 管 理 员 密 码\n");System.out.println("3. 退 出\n");System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");}void loginMenu(){System.out.println("欢迎使用我行我素购物管理系统");System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");System.out.println("  1. 客 户 信 息 管 理\n");System.out.println(" 2. 购 物 结 算\n");System.out.println("3. 真 情 回 馈\n");System.out.println(" 4. 注 销 ");System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");}void guestManage(){System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");System.out.println(" 1. 显 示 所 有 客 户 信 息\n");System.out.println(" 2. 添 加 客 户 信 息\n");System.out.println(" 3. 修 改 客 户 信 息\n");System.out.println(" 4. 查 询 客 户 信 息");System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");}void repairMessage(){System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");System.out.println("1.修 改 会 员 生 日.");System.out.println("2.修 改 会 员 积 分.");System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");}void feedBack(){System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");System.out.println("1. 幸 运 大 放 送\n");System.out.println("2. 幸 运 抽 奖\n");System.out.println("3. 生 日 问 候\n");System.out.println("4.退出");System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");}}/* * 定义物品类 * 属性  名字  价格  编号  总数量 */class  shopping {String name;int price;int num;int number;}/* * 定义会员类 * 属性  生日  卡号  积分 */class VipArray{String Vipbirth;int VipCard;int VipScore;}/* * 客户信息类 * 成员变量   厨师会员个数number 会员类数组VipArray[] * showGuestMessage() 显示客户信息 * addGuestMessage() 添加客户信息 *  repairGuestMessage() 修改客户信息 * search() 查找客户  */class GuestMessage{int number = 6;Scanner input = new Scanner(System.in);VipArray[] tmp = new VipArray[100];//初始化代码块{     tmp[0] = new VipArray();//为数组类成员开辟空间     tmp[0].VipCard = 1900;     tmp[0].Vipbirth = "08/05";     tmp[0].VipScore = 2000;     tmp[1] = new VipArray(); //为数组类成员开辟空间       tmp[1].VipCard = 1711;     tmp[1].Vipbirth = "07/13";     tmp[1].VipScore =4000;     tmp[2] = new VipArray(); //为数组类成员开辟空间      tmp[2].VipCard = 1623;     tmp[2].Vipbirth = "06/26";     tmp[2].VipScore = 5000;     tmp[3] = new VipArray();//为数组类成员开辟空间     tmp[3].VipCard = 1545;     tmp[3].Vipbirth = "04/08";     tmp[3].VipScore = 2000;     tmp[4] = new VipArray();//为数组类成员开辟空间     tmp[4].VipCard =1464;     tmp[4].Vipbirth = "08/16";     tmp[4].VipScore = 2200;     tmp[5] = new VipArray();//为数组类成员开辟空间     tmp[5].VipCard =1372;     tmp[5].Vipbirth = "12/23";     tmp[5].VipScore = 3000;     tmp[6] = new VipArray();//为数组类成员开辟空间     tmp[6].VipCard =1286;     tmp[6].Vipbirth = "12/21";     tmp[6].VipScore = 10080;              }     /*      * 显示所有客户      *      */void showGuestMessage(){System.out.println("我行我素购物管理系统 > 客户信息管理 > 显示客户信息");System.out.println("会员号\t生日\t积分");System.out.println("------|-------|-------|");for( int i = 0; i<=number;i++){System.out.println(tmp[i].VipCard+"\t"+tmp[i].Vipbirth+"\t"+tmp[i].VipScore);}}/* * 添加会员 * 成员变量   YN 询问判断是否继续 */void addGuestMessage(){String YN; do{System.out.println("我行我素购物管理系统 > 客户信息管理 > 添加客户信息\n");System.out.print("请输入会员号(<4位整数>):");int addGuestCard = input.nextInt();System.out.print("请输入会员生日(月/日<用两位数表示>):");String addGuestBirth = input.next();System.out.print("请输入积分:");int addGuestScore = input.nextInt();System.out.println("新会员添加成功!\n继续添加会员吗?(y/n)");YN= input.next();//将新添加客户信息存储if(number <= 100){number++;tmp[number] = new VipArray();tmp[number].Vipbirth = addGuestBirth ;tmp[number].VipCard  = addGuestCard;tmp[number].VipScore = addGuestScore;}}while(YN.equals("y"));}/* * 修改客户信息 * 成员变量  k(switch)  TY 询问判断是否继续   VipCard输入会员卡号 *  */void repairGuestMessage(showMenu obj ){int k;String TY ;System.out.print("请输入会员号:");int VipCard = input.nextInt();System.out.println("会员号\t生日\t积分");System.out.println("------|-------|-------|");//遍历判断卡号是否存在for(int i = 0 ;i<=number;i++){if(VipCard == tmp[i].VipCard){do{System.out.println(tmp[i].VipCard+"\t"+tmp[i].Vipbirth+"\t"+tmp[i].VipScore);obj.repairMessage();System.out.println("请选择,输入数字:");k =input.nextInt();switch(k){case 1:System.out.print("请输入修改后的生日:");String repairBirth = input.next();tmp[i].Vipbirth = repairBirth;System.out.println("生日信息已更改!");break;case 2:System.out.print("请输入修改后的积分:");int  repairScore = input.nextInt();tmp[i].VipScore = repairScore;System.out.println("会员积分已更改!");break;}System.out.println("是否修改其他属性(y/n):");TY = input.next();}while(TY.equals("y"));}}//判断返回上级菜单System.out.print("\n请按'n'返回上一级菜单:");if(input.next().equals("n")){obj.guestManage();}}/* * 查找 * 成员变量 Card输入卡号 */void search(){String NY;System.out.println("我行我素购物管理系统 > 客户信息管理 > 查询客户信息");do{System.out.print("请输入会员号:");int Card = input.nextInt();System.out.println("会员号\t生日\t积分");System.out.println("------|-------|-------|");for(int i = 0 ;i <=number;i++){if(Card ==tmp[i].VipCard){System.out.println( tmp[i].VipCard+"\t"+tmp[i].Vipbirth+"\t"+tmp[i].VipScore);break;}else{System.out.println("抱歉,没有你查询的会员信息。");}}System.out.print("要继续查询吗(y/n):");NY = input.next();}while(NY.equals("y"));}}/* * 多层switch显示类 * secondSwitch() 二级菜单显示购物管理 * thirdSwitch() 三级菜单显示客户信息管理 */class showSwitch{Scanner input = new Scanner(System.in);//购物管理void secondSwitch(showMenu tmp,feedBack prize,GuestMessage objguest,shoppingAccount shop ){tmp.loginMenu();System.out.print("请选择,输入数字:");int i = input.nextInt();switch(i){case 1:thirdSwitch(prize,tmp,objguest,shop);System.out.print("\n请按'n'返回上一级菜单:");if(input.next().equals("n")){secondSwitch(tmp,prize,objguest,shop);}break;case 2:shop.show(objguest);System.out.print("\n请按'n'返回上一级菜单:");if(input.next().equals("n")){secondSwitch(tmp,prize,objguest,shop);}break;case 3:prize.show(tmp,objguest);//showMenu tmp,GuestMessage max System.out.print("\n请按'n'返回上一级菜单:");if(input.next().equals("n")){secondSwitch(tmp,prize,objguest,shop);}break;case 4:tmp.firstMenu();break;}}//客户信息管理void thirdSwitch(feedBack prize,showMenu tmp,GuestMessage objguest,shoppingAccount shop ) {tmp.guestManage();System.out.print("请输入数字:");int i = input.nextInt();switch(i){case 1:objguest.showGuestMessage();break;case 2:objguest.addGuestMessage();break;case 3:objguest.repairGuestMessage(tmp);break;case 4:objguest.search();break;default :thirdSwitch(prize,tmp,objguest,shop);break;}System.out.print("\n请按'n'返回上一级菜单:");if(input.next().equals("n")){secondSwitch( tmp,prize,objguest,shop);}}}/* * 购物结算 * 成员变量: shopping[]物品清单数组  i:总金额  money[]当前购物当前商品总金额 */class shoppingAccount{Scanner input = new Scanner(System.in);shopping []tmp = new shopping[7];//GuestMessage obj = new GuestMessage();int i=0 ; double [] money = new double[100];//初始化物品清单{tmp[0] = new shopping();//为数组类成员开辟空间tmp[0].name = "addidas运动鞋";tmp[0].num = 1;tmp[0].price = 300;tmp[1] = new shopping();//为数组类成员开辟空间tmp[1].name = "Kappa网球裙";tmp[1].num = 2;tmp[1].price = 100;tmp[2] = new shopping();//为数组类成员开辟空间tmp[2].name = "网球拍";tmp[2].num = 3;tmp[2].price = 200;tmp[3] = new shopping();//为数组类成员开辟空间tmp[3].name = "addidasT恤";tmp[3].num = 1;tmp[3].price =50;tmp[4] = new shopping();//为数组类成员开辟空间tmp[4].name = "Nike运动鞋";tmp[4].num = 1;tmp[4].price = 600;tmp[5] = new shopping();//为数组类成员开辟空间tmp[5].name = "Kappa网球";tmp[5].num = 1;tmp[5].price =5;tmp[6] = new shopping();//为数组类成员开辟空间tmp[6].name = "KappaT恤";tmp[6].num = 1;tmp[6].price = 45;}//显示菜单void show(GuestMessage obj){String YN;System.out.println("我行我素购物管理系统 > 购物结算");System.out.println("*************************************");System.out.println("请选择购买的商品编号:");System.out.println("1: addidas运动鞋\n2: Kappa网球裙\n3: 网球拍\n4: addidasT恤\n5: Nike运动鞋\n6: Kappa网球\n7: KappaT恤");System.out.println("*************************************");System.out.print("请输入会员号:");int VipCard = input.nextInt();//遍历判断会员号是否存在for(int m = 0 ; m<=obj.number; m++){if(VipCard == obj.tmp[m].VipCard){//购买商品do{System.out.print("请输入商品编号:");int goodsnum = input.nextInt();System.out.print("请输入数目:");int num = input.nextInt();switch(goodsnum){case 1:money[0] = num * 300;i +=money[0];tmp[0].number+=num;break;case 2:money[1] = num * 100;i+=money[1]; tmp[1].number+=num;break;case 3:money[2] = num * 200;i+=money[2];tmp[2].number+=num;break;case 4:money[3]= num * 50;i+=money[3];tmp[3].number+=num;break;case 5:money[4] = num *600;i+=money[4];tmp[4].number+=num;break;case 6:money[5] = num *5;i+=money[5];tmp[5].number+=num;break;case 7:money[6]= num * 45;i+=money[6];tmp[6].number+=num;break;}System.out.println("是否继续(y/n)");YN= input.next();}while(YN.equals("y"));//输入n时输出消费清单if(YN.equals("n")){System.out.println("*****************消费清单*********************");System.out.println("物品\t单价\t个数\t金额");//循环遍历每个商品是否购买过for(int k = 0; k<7;k++){if(money[k]!=0){System.out.println(tmp[k].name+"\t"+tmp[k].price+"\t"+tmp[k].number+"\t"+tmp[k].number*tmp[k].price);}//if}//forSystem.out.println("折扣 :\t0.85");System.out.println("金额总计:"+i*0.85);System.out.print("实际缴费:");//定义总价及找零和积分int total = input.nextInt();double oddChange = (total-i*0.85);int score = ((int)(i*0.85/100))*3;System.out.println("找钱:"+oddChange);System.out.println("本次购物积分为:"+score);for(int l = 0; l<obj.number;i++){if(obj.tmp[l].VipCard == VipCard){obj.tmp[l].VipScore += score;break;}}}//if}//if}//for}//void}/* * 真情回馈类 * show() 显示界面及switch *  gift() 幸运放送 *  drawPrize() 幸运抽奖 *  birth() 生日问候 */class feedBack{Scanner input = new Scanner(System.in);//显示菜单void show(showMenu tmp,GuestMessage max ){tmp.feedBack();System.out.print("请选择,输入数字:");int num = input.nextInt();switch(num){case 1:gift( max );break;case 2:drawPrize(max );break;case 3:birth( max );break;}}//幸运大放送void gift(GuestMessage max ){System.out.println("我行我素购物管理系统 > 幸运大放送\n");System.out.print("具有最高积分的会员是:");//int maxnum = 0;int index = 0;//找出最大积分for(int i = 0 ; i<=max.number;i++){if(max.tmp[i].VipScore>=max.tmp[index].VipScore){index =i;}}System.out.println(max.tmp[index].VipCard+"\t"+max.tmp[index].Vipbirth+"\t"+max.tmp[index].VipScore);System.out.println("恭喜!获赠礼品: 一个价值¥12000.0的苹果笔记本电脑");}//抽奖void drawPrize(GuestMessage max ){System.out.println("我行我素购物管理系统 > 幸运抽奖");System.out.print("是否开始(y/n):");if(input.next().equals("y")){//随机产生数组中下标int i = (int)(Math.random()*7);System.out.println("幸运客户获赠MP3:"+max.tmp[i].VipCard);}}//生日问候void birth(GuestMessage max ){int bottom = 0;System.out.println("我行我素购物管理系统 > 生日问候\n");System.out.print("请输入今天的日期:");String date = input.next();for(int j = 0; j<=max.number; j++){if(max.tmp[j].Vipbirth.equals(date)){bottom =1;}}if(bottom == 1){System.out.println("恭喜你为超大幸运会员\n这个店你拿去");}else{System.out.println("今天没有过生日的会员!");}}}/* * 登录类 * 成员变量: name: 初始用户名  password 初始密码 * loginManager() 登录 * changeManager() 修改 */class login{Scanner input = new Scanner(System.in);String name = "manager";String password = "0000";   void loginManager(showSwitch tmp,feedBack prize,showMenu tmpshow,GuestMessage objguest,shoppingAccount shop){   System.out.println("请输入用户名:");   String user = input.next();   System.out.println("请输入密码:");   String pass = input.next();if(user.equals(name) && pass.equals(password)){tmp.secondSwitch(tmpshow,prize,objguest,shop);}else{System.out.println("输入错误"); loginManager(tmp,prize,tmpshow,objguest,shop);   }}void changeManager() {System.out.print("请输入用户名:");String olduser = input.next();System.out.print("请输入密码:");String oldpass = input.next();if (olduser.equals(name) && oldpass.equals(password)) {System.out.print("请输入新用户名:");name = input.next();System.out.print("请输入新的密码:");password = input.next();System.out.print("请再次输入密码:");String againNewpass = input.next();System.out.println("用户名和密码已经修改");} else {System.out.println("输入错误 ,重新输入");changeManager();}} }/* * 流程类 *  * show()  */class flow {showMenu obj = new showMenu();Scanner input = new Scanner(System.in);login tmp = new login();showSwitch shous = new showSwitch();feedBack prize = new feedBack();GuestMessage objguest = new GuestMessage();shoppingAccount shop = new shoppingAccount();void show() {obj.firstMenu();while (true) {System.out.print("请选择,输入数字:");int step = input.nextInt();switch (step) {case 1:tmp.loginManager(shous,prize,obj,objguest,shop);break;case 2:tmp.changeManager();break;case 3:System.exit(0);break;}}}}/* * main方法 *  */public class Text{public static void main(String[] args) {flow obj = new flow();obj.show();}}

1 0