package cn.codeengine;
/**
* @author Loger_Chen
*
* @data 2019/9/22
*
* @character UTF-8
*/
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.Random;
import java.util.Scanner;
public class Functions {
ArrayList<Member> members = new ArrayList<Member>();
Scanner scanner = new Scanner(System.in);
// 开卡(注册)
public void registration() {
System.out.print("请输入注册姓名:");
String name = scanner.next();
System.out.print("请输入注册密码:");
String password = scanner.next();
for (; password.length() < 6;) {
System.out.print("对不起!密码的长度不能小于6为,请重新输入密码:");
password = scanner.next();
}
Date cardOpeningDate = new Date();
//生成随机的8为卡号
Random random = new Random();
int cardId = random.nextInt(90000001) + 10000000;
for (Iterator<Member> iterator = members.iterator(); iterator.hasNext();) {
Member aimMember = iterator.next();
//确保卡号的唯一性
for (; aimMember.getCardId() == cardId;) {
cardId = random.nextInt(90000001) + 10000000;
}
}
Member member = new Member(name, cardId, password, 100, cardOpeningDate);
members.add(member);
System.out.println("恭喜,开同会员成功,系统赠送100积分!你的会员卡号为:" + cardId);
}
// 密码修改
public void changePassword() {
System.out.print("请输入你的会员卡号:");
int cardId = scanner.nextInt();
System.out.print("请输入你的会员卡密码:");
String oldPassword = scanner.next();
// 使用迭代器对members进行遍历,并进行用户账号的验证
for (Iterator<Member> iterator = members.iterator(); iterator.hasNext();) {
Member aimMember = iterator.next();
if (aimMember.getCardId() == cardId && aimMember.getPassword().equals(oldPassword)) {
System.out.print("请输入新的会员密码:");
String newPassword = scanner.next();
for (; newPassword.length() < 6;) {
System.out.print("对不起!密码的长度不能小于6为,请重新输入密码:");
newPassword = scanner.next();
}
//对账号信息进行刷新
members.remove(aimMember);
aimMember.setPassword(newPassword);
members.add(aimMember);
System.out.println("密码修改成功!");
} else {
System.out.println("账号或密码错误!");
}
}
}
// 查询剩余积分
public void inquireIntegral() {
System.out.print("请输入你的会员卡号:");
int cardId = scanner.nextInt();
System.out.print("请输入你的会员卡密码:");
String password = scanner.next();
// 使用迭代器对members进行遍历,并进行用户账号的验证
for (Iterator<Member> iterator = members.iterator(); iterator.hasNext();) {
Member aimMember = iterator.next();
if (aimMember.getCardId() == cardId && aimMember.getPassword().equals(password)) {
System.out.println("姓名\t" + "会员卡号\t" + "\t剩余积分\t" + "\t开卡日期\t");
System.out.println(aimMember.getName() + "\t" + aimMember.getCardId() + "\t" + aimMember.getIntegral()
+ "\t\t" + (new SimpleDateFormat().format(aimMember.getCardOpeningDate())));
} else {
System.out.println("账号或密码输入错误!");
}
}
}
// 积分兑换
public void exchangeIntegral() {
System.out.print("请输入你的会员卡号:");
int cardId = scanner.nextInt();
System.out.print("请输入你的会员卡密码:");
String password = scanner.next();
// 使用迭代器对members进行遍历,并进行用户账号的验证
for (Iterator<Member> iterator = members.iterator(); iterator.hasNext();) {
Member aimMember = iterator.next();
if (aimMember.getCardId() == cardId && aimMember.getPassword().equals(password)) {
System.out.print("请输入你需要兑换使用的积分(100积分顶用0.1元,不足100的积分不做抵用):");
int integral = scanner.nextInt();
float money = ((float) ((integral / 100) * 0.1));
if (integral < 100) {
System.out.println("你的消费金额中使用会员积分抵消0.0元");
System.out.println("积分兑换成功!");
} else {
System.out.println("你的消费金额中使用会员积分抵消" + money + "元");
System.out.println("积分兑换成功!");
}
// 对用用户剩余积分进行更新
integral = (int) (aimMember.getIntegral() - money * 1000);
members.remove(aimMember);
aimMember.setIntegral(integral);
members.add(aimMember);
} else {
System.out.println("账号或密码输入错误!");
}
}
}
// 积分累计
public void addIntegral() {
System.out.print("请输入你的会员卡号:");
int cardId = scanner.nextInt();
System.out.print("请输入你的会员卡密码:");
String password = scanner.next();
//
for (Iterator<Member> iterator = members.iterator(); iterator.hasNext();) {
Member aimMember = iterator.next();
if (aimMember.getCardId() == cardId && aimMember.getPassword().equals(password)) {
System.out.print("请输入你此次消费金额(消费一元累计1积分):");
float money = scanner.nextFloat();
members.remove(aimMember);
int newIntegral = aimMember.getIntegral() + (int) money;
aimMember.setIntegral(newIntegral);
members.add(aimMember);
System.out.println("积分累计成功!");
}else {
System.out.println("账号或密码输入错误!");
}
}
}
}
Loger_Chen
- 粉丝: 0
- 资源: 1
最新资源
- springboot项目基于html的网上团购系统设计与实现.zip
- 220v3300w半桥电磁炉源代码 合泰半桥电磁炉ht45f0074 半桥电磁炉,半桥电磁炉程序电磁炉源程序,电磁炉程序代码,电磁炉开发整套资料,合泰HT45F0074综合资料含有单片机源码,主板PC
- springboot项目基于html的民谣网站的设计与实现.zip
- springboot项目基于Java web的药店管理系统的设计与实现.zip
- springboot项目基于javaEE的校园二手书交易平台的设计与实现.zip
- springboot项目基于HTML语言的环保网站的设计与实现.zip
- springboot项目基于JavaWeb的宠物商城网站设计与实现.zip
- springboot项目基于javaweb的学生用品采购系统.zip
- 电网杆塔训练资源voc格式,已划分好train、val、test
- springboot项目基于JavaWeb的鲜牛奶订购系统的设计与实现.zip
- springboot项目基于javaweb的影院订票系统的设计与实现.zip
- springboot项目基于java的火车票订票系统的设计与实现.zip
- springboot项目基于JAVA的房地产销售管理系统的设计与实现.zip
- OpenCV答题卡识别系统C++实现源码+作业报告.zip
- springboot项目基于Java的家政服务平台的设计与实现.zip
- springboot项目基于Java的民宿管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈