2019年2月28日 超市会员管理系统
java源文件分享地址:
链接:https://pan.baidu.com/s/1Ild11O_Vn8ZoKxfQxxwFRw
提取码:k2fr
复制这段内容后打开百度网盘手机App,操作更方便哦
首先创建会员类
package com.demo; public class Member { private String name; private String password; private int integral; private String time; public Member() { } public Member(String name, String password, int integral,String time) { this.name = name; this.password = password; this.integral = integral; this.time = time; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public int getIntegral() { return integral; } public void setIntegral(int integral) { this.integral = integral; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } }
再次编写系统类:
package com.demo; import org.junit.Test; import java.text.SimpleDateFormat; import java.util.*; public class SupermarketMemberSystem { public static void main(String[] args) { Member m1 = new Member("张三","888888",1234,"2019-2-27 19:45:34"); Member m2 = new Member("李四","L456789",25243,"2019-2-26 10:45:34"); Map<String,Member> map = new HashMap<String,Member>(); map.put("88888888",m1); map.put("52342542",m2); Scanner input = new Scanner(System.in); Random random = new Random(); String name; String password; int integral; String time; String key = ""; System.out.println("**************欢迎进入超市会员管理系统***************"); do{ System.out.println("*****************************************************"); System.out.print("1、会员开卡\t\t"); System.out.print("2、会员登入\t\t"); System.out.println("3、结束"); System.out.println("*****************************************************"); System.out.print("请选择:"); String choice1 = input.next(); switch (choice1){ case "1": do{ System.out.print("请输入注册姓名:"); boolean nameFlag = false; do{ name = input.next(); if(name.length()<2){ System.out.println("姓名格式不正确,请重新输入!"); continue; }else { nameFlag = true; break; } }while (true); System.out.println("请输入注册密码:"); boolean passwordFlag = false; do{ password = input.next(); if(password.length()<6){ System.out.println("密码长度太短,请重新输入!"); continue; }else { passwordFlag = true; break; } }while (true); if(nameFlag&&passwordFlag){ System.out.print("恭喜!开通会员卡成功,系统赠送您100积分!"); Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); time = sdf.format(date); integral = 100; int[] nums = new int[8]; boolean keyFlag = true; do{ for(int i = 0 ;i<8;i++){ if(i==0){ nums[i] = random.nextInt(9)+1; }else { nums[i] = random.nextInt(10); } String id =Integer.toString(nums[i]); key +=id; } for(String k:map.keySet()){ if(k.equals(key)){ break; }else { keyFlag = false; } } }while (keyFlag); System.out.println("您的会员卡号为:"+key); Member m = new Member(name,password,integral,time); // System.out.println(m.getName()+m.getPassword()+m.getIntegral()+m.getTime()); map.put(key,m); System.out.println("请用会员卡号重新登入!"); key = ""; break; } }while (true); break; case "2": String kahao = ""; String mima = ""; boolean dengru = true; boolean back1 = false; System.out.println("请输入您的会员卡号:"); do{ kahao = input.next(); boolean kahaoFlag = false; System.out.println("请输入您的会员卡密码:"); mima = input.next(); boolean mimaFlag = false; System.out.print("请输入验证码:"); int[] nums = new int[6]; String yanzhengMa = ""; for(int j= 0;j<nums.length;){ nums[j] = random.nextInt(122); char num; if(nums[j]>=48&&nums[j]<=57){ num =(char) nums[j]; }else if(nums[j]>=65&&nums[j]<=90){ num =(char) nums[j]; }else if(nums[j]>=97&&nums[j]<=122){ num =(char) nums[j]; }else { continue; } System.out.print(num); String nu = Character.toString(num); yanzhengMa += nu; if(j==nums.length-1){ System.out.println(); } j++; } do{ String yanZheng = input.next(); if(yanZheng.equalsIgnoreCase(yanzhengMa)){ break; }else { System.out.println("验证码不正确,请重新输入!"); } }while (true); for(String k:map.keySet()){ if(k.equals(kahao)){ kahaoFlag =true; break; } } if(kahaoFlag){ }else { System.out.println("会员卡号错误!"); } for(Member m : map.values()){ if(m.getPassword().equals(mima)){ mimaFlag = true; break; } } if(mimaFlag){ }else { System.out.println("密码错误!"); } if(kahaoFlag&&mimaFlag){ System.out.println("登入成功!"); dengru = false; }else { System.out.print("登入失败,请重新登入!"); System.out.println("输入“0”返回主页!"); String back = input.next(); if(back.equals("0")){ back1 =true; break; }else { System.out.println("请输入您的会员卡号:"); } } }while (dengru); if(back1){ break; } boolean flag1 = true; do{ System.out.print("1、积分累计\t\t"); System.out.print("2、积分兑换\t\t"); System.out.print("3、会员信息\t\t"); System.out.print("4、修改密码\t\t"); System.out.print("5、退出账号\n"); System.out.print("请选择:"); Scanner input1 = new Scanner(System.in); String choice2 = input1.next(); switch (choice2){ case "1": System.out.print("请输入您此次的消费金额(消费1元累计1积分):"); int pay; try { do{ pay = input1.nextInt(); if(pay<=0){ System.out.println("输入有误,请重新输入:"); }else { break; } }while (true); }catch (InputMismatchException e){ System.out.println("输入有误,退出功能!"); break; }catch (Exception e){ System.out.println("输入有误,退出功能!"); break; } int temp =map.get(kahao).getIntegral()+pay; map.get(kahao).setIntegral(temp); System.out.println("积分累计成功!当前积分为:"+map.get(kahao).getIntegral()); break; case "2": System.out.print("请输入您需要兑换使用的积分(100积分抵用0.1元,不足100的积分不做抵用):"); int duiHuan = 0; do{ try{ do{ duiHuan = input1.nextInt(); if(duiHuan<=0){ System.out.println("输入有误,请重新输入:"); }else { break; } }while (true); }catch (InputMismatchException e){ System.out.println("输入有误,即将退出请重新选择!"); break; }catch (Exception e) { System.out.println("输入有误,即将退出请重新选择!"); break; } if(map.get(kahao).getIntegral()>=100){ if(map.get(kahao).getIntegral()>=duiHuan){ int temp1 =map.get(kahao).getIntegral()-duiHuan; map.get(kahao).setIntegral(temp1); double diYong = duiHuan*1.0/1000; System.out.println("您的消费金额中使用会员积分抵消"+diYong+"元,剩余积分:"+map.get(kahao).getIntegral()); break; }else { System.out.println("您的积分不足,请重新输入!"); continue; } }else { System.out.println("您的积分不足100,不能抵用!"); break; } }while (true); break; case "3": System.out.println("姓名\t\t"+"会员卡号\t\t"+"剩余积分\t\t"+"开卡日期"); System.out.println(map.get(kahao).getName()+"\t\t"+kahao+"\t\t"+map.get(kahao).getIntegral()+"\t\t"+map.get(kahao).getTime()); break; case "4": String mimaNew1; String mimaNew2; System.out.println("请输入新密码:"); do{ mimaNew1 = input.next(); if(mimaNew1.length()<6){ System.out.println("密码位数不能小于6,请重新输入:"); continue; }else if(mimaNew1.equals(map.get(kahao).getPassword())){ System.out.println("新密码与原密码不能相同!请重新输入:"); continue; }else { break; } }while (true); System.out.println("请再次输入新密码:"); do{ mimaNew2 = input.next(); if(mimaNew1.equals(mimaNew2)){ System.out.println("修改密码成功!"); map.get(kahao).setPassword(mimaNew2); break; }else { System.out.println("两次输的新密码要相同!请重新输入:"); } }while (true); break; case "5": flag1 = false; break; default: System.out.println("输入有误,请重新输入!"); } }while (flag1); break; case "3": System.out.println("祝您生活愉快!"); return; default: System.out.println("输入有误,请重新输入!"); } }while (true); } }
输出结果为:
"C:\Program Files\Java\jdk1.8.0_191\bin\java.exe" "-javaagent:G:\IntelliJ IDEA 2018.3.1\lib\idea_rt.jar=53503:G:\IntelliJ IDEA 2018.3.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_191\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\rt.jar;G:\超市会员管理系统\out\production\超市会员管理系统;C:\Users\刘铭辉\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\刘铭辉\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.demo.SupermarketMemberSystem **************欢迎进入超市会员管理系统*************** ***************************************************** 1、会员开卡 2、会员登入 3、结束 ***************************************************** 请选择:1 请输入注册姓名:admin 请输入注册密码: 888888 恭喜!开通会员卡成功,系统赠送您100积分!您的会员卡号为:60512122 请用会员卡号重新登入! ***************************************************** 1、会员开卡 2、会员登入 3、结束 ***************************************************** 请选择:2 请输入您的会员卡号: 60512122 请输入您的会员卡密码: 888888 请输入验证码:RpFepk rpfepk 登入成功! 1、积分累计 2、积分兑换 3、会员信息 4、修改密码 5、退出账号 请选择:3 姓名 会员卡号 剩余积分 开卡日期 admin 60512122 100 2019-03-01 14:26:59 1、积分累计 2、积分兑换 3、会员信息 4、修改密码 5、退出账号 请选择:1 请输入您此次的消费金额(消费1元累计1积分):10000 积分累计成功!当前积分为:10100 1、积分累计 2、积分兑换 3、会员信息 4、修改密码 5、退出账号 请选择:2 请输入您需要兑换使用的积分(100积分抵用0.1元,不足100的积分不做抵用):5000 您的消费金额中使用会员积分抵消5.0元,剩余积分:5100 1、积分累计 2、积分兑换 3、会员信息 4、修改密码 5、退出账号 请选择:4 请输入新密码: 888888 新密码与原密码不能相同!请重新输入: 111111 请再次输入新密码: 111111 修改密码成功! 1、积分累计 2、积分兑换 3、会员信息 4、修改密码 5、退出账号 请选择:5 ***************************************************** 1、会员开卡 2、会员登入 3、结束 ***************************************************** 请选择:3 祝您生活愉快! Process finished with exit code 0