package service.impl;
import service.MemberService;↵
public class MemberServiceImpl implements MemberService { MemberDao mb - new MemberDaoImp();@Override
public void a() {
// TODO Auto-generated method stub mb.a();}
@Override
public void b() {
// TODO Auto-generated method stub mb.b();
}
@0verride
public void c() {
// TODO Auto-generated method stub mb.c();|}
@Override
public void d() {
// TODO Auto-generated method stub mb.d();}
@0verride
public void f(){
// TODO Auto-generated method stub mb,f();}
@
public void e(){
// TO0O Auto-generated method stub mb.e();}
package dao;
public interface MemberDao
void a();//注册
void b();//积分累计
void c();//积分兑换
void d();//积分查询
void f();//修改密码
void e();//退出}
package entity;
public class Member{
private String name; private int cardld;
private String password;
private int score;
private String registDate;
p.java private int coin;
public String getName(){
return name;
public void setName(String name){
this.name - name;
jva return cardld; public int getCardld(){
}
vaSE-1.6] Impl.java this.cardld = cardld; public void setCardld(int cardld){
public int getCoin() {
return coin;
public void setCoin(int coin){
this.coin - coin;
public String getPassword(){
return password;}
public void setPassword(String password) {
this.password - password;
public int getScore(){
return score;
public void setScore(int score){
this.score = score;
public String getRegistDate(){
return registDates
public void setRegistDate(String registDate) {
this.registDate registDate;
public Member(){
}
public Membee(String name ,int cardld, String password,int score,
String registDate,int coin){
this.name =name;
this.cardld =cardld;
this.password=password;
this.score=score;
this.registDate =registDate;
this.cion=coin;
import java.sql.SQLOutput;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class MemberDao {
static Scanner sc = new Scanner(System.in);
static List<Member> rv = new ArrayList<>();
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(); // 消耗换行符
switch (choice) {
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 = LocalDateTime.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 Member hasMember(Member member){
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++){
if(member.getCardID() == rv.get(i).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(i,member);
return true;
}
}
}
return false;
}
public int create(){
LocalDateTime date = LocalDateTime.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;
}
}
}
return false;
}
}
package main;
@import java.uti1.Scanner;↵ public class Menu {
Scanner input - new Scanner(System.in);
MemberServiceImpI msi-new MemberServiceImp1(); public void Showmwnu(){
// TODO Auto-generated method stub
while(true){ System.out.println("****** *************************);
************************);
System.out.println("1.注册 2.累计 3.兑换4.查询5.修改 6.退出"); System.out,println("*******
System.out.println("请选择"); int d-input.nextInt(); if(d==1){
msi.a();
}else if(d==2){
_msi.b();
}elde if(d==3){
msi.c();
}else if(d==4){
msi.d();
}else if(d==5){
msi.f();
}else if(d==6){
msi.e(); return ;}else {
System.out.println("没有选项,重新输入"); break;}
}}
}
标签:member,青青,int,System,网校,println,public,商城,out From: https://blog.csdn.net/2402_82418339/article/details/139724941