import java.sql.SQLOutput;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;j
import ava.util.ArrayList;
import iava.util.List;
import iava.util.Scanner;
public class MemberDao{
static Scanner sc=newScanner(System.in);
static ist<Member>rv=new rrayList<>();
static Member member=new Member);
public void menu(){
boolean flag = true;
while(flag){
System.out.println("青青网校积分商城");
System.out.println("1.注册");
System.out.println("2.积分累计");
System.out.println("3.积分兑换");积分查询");
System.out.println("4.System.out.println("5.修改密码");
System.out.println("6.退出");
System.out.print("请选择操作:");
int choice =sc.nextInt();
sc.nextLine();
case 1:
register();
break;
case 2:
System.out.println("请输入你的会员编号:");
int card=sc.nextInt();
System.out.println("请输入会员密码");
String pwd = sc.nextLine();
member =hasMember(new Member(card,pwd));
if(member !=null){
boolean RE=saveMember();
if(RE){
System.out.println("ok");
}else{
System.out.println("error");
}
}
break;
case 3:
System.out.println("请输入你的会员编号:");
int C=sc.nextInt();
System.out.println("请输入会员密码");
String P=sc.nextLine();
member=hasMember(new Member(C,P));
if(member !=null){
System.out.println("你当前积分是:"+member.getScore());
System.out.println(minusMember() ? "ok" : "error");
break;
case 4:
System.out.println("请输入你的会员编号:");
int Cs = sc.nextInt();
System.out.println("请输入会员密码");
String Ps=sc.nextLine();
member =hasMember(new Member(Cs,Ps));
if(member != null){
show();
}
break;
case 5:
changePwd();
break;
case 6:
flag = false;
break;
default:
System.out.println("无效的选择,请重新输入。");
}
}
}
public void start(){
menu();
}
public void register(){
System.out.print("请输入注册姓名:String name = sc.nextLine();
System.out.print("请输入注册密码:");
String pwd = sc.nextLine();
String date =ocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm.ss"));
int card=create();
boolean res =rv.add(new Member(name ,card,pwd,100,date));
if(res){
System.out.println("ok");
}else {
System.out.println("error");
}
}
public Memoer nasMemoer (Memoer memoer){
for(int i=0;i < rv.size();i++){
Member m=rv.get(i);
if(m.getCardID()==member.getCardID()&& m.getPassword().equals(member.getPassword())){
return rv.get(i);
}
}
return null;
}
public boolean saveMember(){
System.out.println("请输入消费金额:");
int ef= sc.nextInt();
member.setScore(member.getScore()+ef);
for(int i=0;i < rv.size();i++){
f(member.getCardID()rv.set(i,member);return true;rv.qet(1).getCardID()){
rv.set(i member);
return true;
}
}
return false;
}
public boolean minusMember(){
System.out.println("请输入你要兑换使用的积分:");
int ef= sc.nextInt();
if(ef >=100 && ef %100 ==0){
member.setScore(member.getScore()-ef);
System.out.println("你本次兑换"+(ef/100)+"剩余积分;+“member.getScore());
for(int i =0;i < rv.size();i++){
if(member.getCardID()== rv.get(i).getCardID()){
rv.set(1memoer);
return true;
}
}
return false;
public int create(){
LocalDateTime date =ocalDateTime.now();
String s=DateTimeFormatter.ofPattern("hhmmss").format(date);
int id =0;
if(rv.size() <=0){
s= s+"001";
id = Integer.parseInt(s);
}else {
id =rv.get(rv.size()-1).getCardID();
}
return 0;
}
public void show(){
System.out.println("姓名"+member.getName());
System.out.println("编号"+member.getCardID());
System.out.println("积分"+member.getScore());
System.out.println("时间"+member.getRegisDate());
}
public boolean changePwd()
System.out.println("请输入你的会员编号:");
int Cs =sc.nextInt();
System.out.println("请输入会员密码");
String Ps=sc.nextLine();
member =hasMember(new Member(Cs,Ps));
if(member != null){
System.out.println("请输入修改后的密码");
member.setPassword(sc.next());
for(int i=0;i< rv.size();i++){
if(member.getCardID()==rv.get(i).getCardID()){
rv.set(i member);
return true;
}
false;
public class TestMain{
public static void main(String[]args){
MemberDao memberDao=new MemberDao();
memberDao.start();
}
}
public class Member {
private String name;
private int cardID;private String password;
private int score;
private String regisDate;
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getRegisDate(){
return regisDate;
}
public void setRegisDate(String regisDate)
this.reqisDate =regisDate;
}
public int getscore(){
return score;
}
public String getPassword(){
return password;
}
public void setPassword(String password){
this.password=password;
}
public int getCardID(){
return cardID;
}
public void setCardID(int cardID){
this.cardID=ardID;
}
public Member(String name,int cardID,String password,int score,String regisDate){
this.name= name ;
this.cardID =cardD;
this.password = password;
this.score= SCoerthis.reqisDate =regisDate;
}
public Member(){ }
public Member(intcardID,String password)
this.cardID = cardID;
this.password =password;
}
}