Keperluan: Gunakan rangka kerja pengumpulan dan kelas utiliti untuk melaksanakan sistem
1 Pengumpulan mata
2 Penebusan mata
3 . Tukar kata laluan
5. Buka kad
6. Keluar
Hasil pelaksanaan:
Bahagian pembukaan kad dan pengumpulan mata: Tebus mata dan semak baki mata: Tukar kata laluan dan gunakan kata laluan baharu untuk menyemak: Bahagian keluar: Idea pelaksanaan:1. Cipta kelas pengguna ahli:
Buat kelas perniagaan pasar raya:
3. Kelas ujian
Kod sumber: Kelas pengguna ahlipackage cn.zyq.Aug0203; /** * 会员用户类 * @author admin * */ public class Member { //姓名 private String name; //密码 private String pwd; //会员卡号 private String id; //注册日期 private String registData; //积分 private int score; public Member() { } public Member(String name, String pwd, String id, String registData, int score) { super(); this.name = name; this.pwd = pwd; this.id = id; this.registData = registData; this.score = score; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getRegistData() { return registData; } public void setRegistData(String registData) { this.registData = registData; } public int getScore() { return score; } public void setScore(int score) { this.score = score; } }Kelas perniagaan pasar raya
package cn.zyq.Aug0203; /** * 超市业务类 */ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Random; import java.util.Scanner; public class Business { Scanner sc = new Scanner(System.in); List<Member> list = new ArrayList<Member>(); /** * 用户可选择菜单 */ public void init() { System.out.println("\n--------------------欢迎进入会员管理系统--------------------\n"); System.out.println("1.积分累计 2.积分兑换 3.查询剩余积分 4.修改密码 5.开卡 6.退出"); System.out.println("\n-------------------------------------------------------"); System.out.println(); System.out.print("请选择您要进行的操作:"); choose(sc.nextInt()); } /** * 用户选择的业务 * @param num */ public void choose(int num) { switch (num) { case 1: saveScore(); break; case 2: useScore(); break; case 3: search(); break; case 4: updatePwd(); break; case 5: regist(); break; case 6: System.out.println("欢迎下次光临!"); System.exit(0); break; } init(); } /** * 积分积累 */ public void saveScore() { Member m = check(); if(m!=null) { System.out.print("请输入您消费的金额(一元一积分):"); int score = sc.nextInt(); m.setScore(m.getScore()+score); System.out.println("积分增加成功,目前您的积分为:"+m.getScore()); System.out.println("积分累计成功!"); }else { System.out.println("积分累计失败,您输入的信息有误!"); } } /** * 积分兑换 */ public void useScore() { Member m = check(); if(m!=null) { System.out.print("请输入您需要兑换使用的积分(100积分抵用1元,不足100的积分不做抵用):"); int score = sc.nextInt(); if(m.getScore()>=100 && score>=100 && score<=m.getScore()) { m.setScore(m.getScore()-score); System.out.println("您本次消费抵用金额为:"+score/100); System.out.println("兑换积分成功!"); }else { System.out.println("兑换积分失败,账户积分不足或需要兑换积分大于剩余积分!"); } }else { System.out.println("账号信息不匹配,无法兑换积分!"); } } /** * 查询剩余积分 */ public void search() { Member m = check(); if(m!=null) { System.out.println("姓名\t会员卡号\t剩余积分\t开卡日期"); System.out.println(m.getName()+"\t"+m.getId()+"\t"+m.getScore()+"\t"+m.getRegistData()); }else { System.out.println("输入的账号信息不匹配!"); } } /** * 修改密码 */ public void updatePwd() { Member m = check(); if(m!=null) { System.out.print("请输入您的新密码:"); String pwd = sc.next(); //重新设置密码 m.setPwd(pwd); System.out.println("密码修改成功!"); }else { System.out.println("输入的账号信息不匹配,无法进行此业务!"); } } /** * 积分兑换 */ public void regist() { System.out.print("欢迎使用本超市会员卡,请输入您的姓名:"); String name = sc.next(); System.out.print("请设置您的密码(要求密码长度大于6):"); String pwd = sc.next(); //判断密码是否合法 boolean flag = false; while(!flag) { if(pwd.length()<6) { flag = false; System.out.print("密码长度小于6位,请重新输入密码:"); pwd = sc.next(); } else { flag = true; } } //生成一个八位数的随机会员卡号 Random random = new Random(); int rand = random.nextInt(999999); String id = String.valueOf(rand); //判断会员卡是否已存在 for(Member m:list) { if(m.getId()==id) { rand = random.nextInt(99999999); id = String.valueOf(rand); } } //注册日期 Date date = new Date(); SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss"); String registData = dateFormat.format(date); //开卡送积分100; int score = 100; //将用户记录添加到列表 list.add(new Member(name, pwd, id, registData, score)); System.out.println("恭喜你成为本超市会员,系统赠送您100积分,您的会员卡号为:"+id+",请牢记卡号和密码!"); } /** * 信息检测,list中是否存有指定用户信息 */ public Member check() { System.out.print("请输入您的会员卡号:"); String id = sc.next(); System.out.print("请输入您的密码:"); String pwd = sc.next(); for(Member m:list) { if(m.getId().equals(id) && m.getPwd().equals(pwd)) { return m; } } return null; } }Kelas ujian
package cn.zyq.Aug0203; /** * 测试类 * @author admin * */ public class Test { public static void main(String[] args) { Business business = new Business(); business.init(); } }
Atas ialah kandungan terperinci Langkah dan kaedah pelaksanaan melaksanakan sistem pengurusan keahlian pasar raya di Jawa. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!