今天记录一个实战项目,超市会员积分商城,用集合框架和实用类实现,不带数据库。要求:
1.有登录界面,有登录状态,能注册会员
2.会员卡可以开卡,积分
3.能查询剩余积分
4.积分累计,积分兑换
5.修改密码
6.退出
思路:主要有会员类,会员卡类,商品类,商城类,测试类
会员类:属性就有用户名,密码,身份证号,手机号,会员卡,因为设定是一人一卡,因此会员有两个属性用于记录状态,一个是登录状态,一个是是否使用积分兑换过的状态,我设定的是每人每天只能兑换一次,因此有这个状态需要记录。
public class Member {
private String name;
private String password;
private String iD;
private int cellphoneNo;
private Card membercard;
private boolean loginFlag;
private boolean usepointsFlag;
public Member() { }
public boolean isUsepointsFlag() { return usepointsFlag; }
public void setUsepointsFlag(boolean usepointsFlag) { this.usepointsFlag = usepointsFlag; }
public boolean isloginFlag() { return loginFlag; }
public void setloginFlag(boolean loginFlag) { this.loginFlag = loginFlag; }
public String getPassword() {
return password;
}
public void setPassword(String password) {
if(password.length()<8){
System.out.println("密码长度不能小于8");
}else
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) { this.name = name; }
public String getiD() {
return iD;
}
public void setiD(String iD) {
this.iD = iD;
}
public int getCellphoneNo() {
return cellphoneNo;
}
public void setCellphoneNo(int cellphoneNo) {
this.cellphoneNo = cellphoneNo;
}
public void setMembercard(Card membercard) { this.membercard = membercard; }
public Card getMembercardNo() {
return membercard;
}
public String changepassword(Member m){
Scanner sc=new Scanner(System.in);
Shoppingmall sm=new Shoppingmall();
System.out.println("请输入旧密码:");
String old=sc.next();
if (old.equals(getPassword())){
do{ System.out.println("请输入新密码:");
String newpass=sc.next();
setPassword(newpass);
System.out.println("密码修改成功,您的新密码是"+getPassword());}while (getPassword()==old);
}else {
System.out.println("忘记密码选1,重新输入选2,其他任意键退回首页");
int chose = sc.nextInt();
switch (chose) {
case 1:findbackpassword(m);break;
case 2:changepassword(m);break;
default:sm.firstpage(m);break;
}
}
return password;
}
public void findbackpassword (Member m){
Scanner sc=new Scanner(System.in);
Shoppingmall sm=new Shoppingmall();
System.out.println("找回密码请输入身份证号:");
String no=sc.next();
if(no==getiD()){
System.out.println("您的密码是:"+getPassword());
}else {
System.out.println("身份证号输入错误,无法找回密码,请携带身份证到柜台办理!");
}
}
}
会员卡类:会员卡的属性就很简单,卡号,密码,积分和等级,不过写到后面我自己把等级这回事儿给忘了所以没什么实际用处,回头可以改成只有VIP等级才能兑换某些商品。
public class Card {
private int cardNo;
private String password;
private int points;
private int level;
public void setCardNo(int cardNo) {
this.cardNo = cardNo;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}
public Card() {
}
public int getCardNo() {
return cardNo;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String changepassword(Member m){
Scanner sc=new Scanner(System.in);
Shoppingmall sm=new Shoppingmall();
System.out.println("请输入旧密码:");
String old=sc.next();
if (old.equals(getPassword())){
do{ System.out.println("请输入新密码:");
String newpass=sc.next();
setPassword(newpass);
System.out.println("密码修改成功