import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
static Admin[] admins = new Admin[2];//初始化一个容量为2的管理员静态对象数组
static Person[] people = new Person[10];//初始化一个容量为10的静态动象数组
static boolean logIndex = false;//是否登录成功标识
static boolean mgrLogIndex = false;//管理员是否登录成功标志
static int index ;//对象数组索引
static boolean isBan = false;//是否为禁用状态
static boolean isChangPwd = false;//是否为改变密码的状态
static boolean isExitLog = false;//是否退出登录
static boolean noExit = true;//退出循环标志
public void init() {//初始化对象数组
people[0] = new Person(9832, "张三", "123456", "湖北武汉", "15673459878", "1950.09.10", 200, 200, 1);
people[1] = new Person(1543, "张五", "12345.", "湖北武汉", "15372459878", "2000.08.18", 2000, 2000, 1);
people[2] = new Person(1934, "李四", "admin", "湖北襄阳", "15673459878", "2001.02.10", 100, 400, 1);
people[3] = new Person(1124, "刘七", "admin", "湖北襄阳", "15673459878", "2001.02.10", 100, 190, 1);
people[4] = new Person(1234, "王五", "admin", "湖北襄阳", "15673459878", "2001.02.10", 1100, 19, 0);
admins[0] = new Admin(8888,"小二","admin");
admins[1] = new Admin(6666,"超管","superadmin");
}
public void log() {
System.out.print("请输入账号:");
int pid = sc.nextInt();
System.out.print("请输入密码:");
String password = sc.next();
for (int i = 0; i 999) {//判断积分如果大于等于1000进入积分换购
showChangeGoods();
System.out.print("请选择换购的物品:");
int select = sc.nextInt();
switch (select) {
case 1:
people[index].setJifen(people[index].getJifen() - 200);
break;
case 2:
people[index].setJifen(people[index].getJifen() - 1000);
break;
case 3:
people[index].setJifen(people[index].getJifen() - 300);
break;
case 4:
people[index].setJifen(people[index].getJifen() - 500);
break;
}
}else {//否则输出积分不足
System.out.println("您的积分不足!不能参加积分换购活动!!");
}
}
public static void main(String[] args) throws ParseException {
Person person = new Person();
Admin admin = new Admin();
Main main = new Main();
main.init();//初始化数据
do {
System.out.println("**商城客户信息管理系统**");
System.out.println("t1,会员登录");
System.out.println("t2,管理员登录");
System.out.println("********************");
System.out.print("请选择:");
int input = sc.nextInt();
switch (input) {
case 1:
main.log();//登录
if (isBan) {//判断是否被禁用
System.out.println("您的账户被禁用!不能使用登录!");
}
else {
do {
if (logIndex) {
person.showMenu(people[index]);
System.out.print("请输入选项:");
int select = sc.nextInt();
switch (select) {
case 1://查看信息
person.showAll(people[index]);
break;
case 2://充值
System.out.print("请输入充值金额:");
double money = sc.nextDouble();
people[index].setMoney(money + people[index].getMoney());//冲进去的金额
people[index].setJifen((int) money + people[index].getJifen());//冲多少得多少积分
System.out.println("您的余额是:" + people[index].getMoney());
break;
case 3://修改密码
System.out.print("请输入原密码:");
String pwd = sc.next();
main.changPwd(pwd);
isChangPwd = true;//修改了密码!!
System.out.println("请重新登录");
break;
case 4://参加积分换购活动
main.jifenRes(people[index].getJifen());
break;
default://退出
System.out.println("正在退出...");
isExitLog = true;
break;
}
} else {
System.out.println("账号或密码错误!");
break;
}
if (isChangPwd || isExitLog) {//判断是否改密码了 或则 是否退出了
noExit = false; //如果上面成立一条就返回 false 退出do while 循环
}
} while (noExit);//相当于退出登录
break;
}
break;
case 2:
main.MrgLog();// 管理员登录
do {
if (mgrLogIndex) {//管理员登录标志为true则执行下面
admin.shwoMenu(admins[index]);
System.out.print("请输入选项:");
int select = sc.nextInt();
switch (select) {
case 1://添加会员
main.addVip();
break;
case 2://查看所有会员信息
main.showAllVip();
break;
case 3://查看年龄30岁以下的会员信息
System.out.println("小于30岁的客户信息有");
main.showBelow30();
break;
case 4://查看年龄60岁以上的会员信息
System.out.println("大于60岁的客户信息有");
main.above60();
break;
case 5://统计不同等级的会员人数
main.showDifVip();
break;
case 6://会员状态变更
main.changeStatus();
break;
default://退出
System.out.println("正在退出...");
isExitLog = true;
break;
}
} else {
System.out.println("账号或密码错误!");
break;
}
if (isChangPwd || isExitLog || isBan) {
noExit = false;
}
} while (noExit);
break;
default:
System.out.println("正在退出系统.......");
return;
}
} while (true);
}
public void showAllVip() {
System.out.println("姓名ttt会员编号ttt密码tttt地址tttt电话ttttt生日ttttt积分tttt余额tttt会员状态");
for (Person person : people) {
if (person != null) {
System.out.println("姓名:" + person.getName() +
"tt会员编号:" + person.getPid() +
"tt密码:" + person.getPassword() +
"tt地址:" + person.getAddress() +
"tt电话:" + person.getPhone() +
"tt生日:" + person.getBirthday() +
"tt积分:" + person.getJifen() +
"tt余额:" + person.getMoney() +
"tt状态:" + person.getStatus());
}
}
}
private void addVip() throws ParseException {
for (int i = 0; i < people.length; i++) {
if (people[i] == null) {//判断如果有空的对象数组就添加
System.out.print("请输入pid:");
int pid = sc.nextInt();
System.out.print("请输入会员姓名:");
String name = sc.next();
String password;
do {
System.out.print("请输入密码:");
password = sc.next();
String regexPwd = "\w{6,12}";
if (!password.matches(regexPwd)) {
System.out.println("您的密码格式有问题!请重新输入");
continue;
} else {
break;
}
} while (true);
System.out.print("请输入地址:");
String address = sc.next();
String tel;
do {
System.out.print("请输入电话:");
tel = sc.next();
String regTel = "^1[35789]\d{9}";
if (!tel.matches(regTel)) {
System.out.println("您输入的电话格式不正确!请重新输入!");
continue;
} else {
break;
}
} while (true);
System.out.print("请输入生日:");
String bir = sc.next();
if (getAge(bir) > 18) {
System.out.print("请输入积分:");
int jifen = sc.nextInt();
System.out.print("请输入余额:");
double money = sc.nextDouble();
System.out.print("请输入状态:(0/1)");
int status = sc.nextInt();
people[i] = new Person(pid, name, password, address, tel, bir, jifen, money, status);
System.out.println("是否要退出添加?(y/其他)");
String isAdd = sc.next();
if (!isAdd.equals("y")) {
break;
}
} else {
System.out.println("未满18禁止添加!!!");
break;
}
}
}
}
private void showBelow30() throws ParseException {
if (mgrLogIndex) {
for (int i = 0; i < people.length; i++) {
if (people[i] != null && getAge(people[i].getBirthday()) < 30) {
System.out.print("姓名:" + people[i].getName() + " ");
System.out.print("密码:" + people[i].getPassword() + " ");
System.out.print("地址:" + people[i].getAddress() + " ");
System.out.print("pid:" + people[i].getPid() + " ");
System.out.print("生日:" + people[i].getBirthday() + " ");
System.out.print("积分:" + people[i].getJifen() + " ");
System.out.print("电话:" + people[i].getPhone() + " ");
System.out.print("余额:" + people[i].getMoney() + " ");
System.out.print("状态:" + people[i].getStatus() + "n");
}
}
}
}
public long getAge(String getBirthday) throws ParseException {
SimpleDateFormat get = new SimpleDateFormat("yyyy.MM.dd");
Date date = get.parse(getBirthday);
Date nowDate = new Date();
long nowDateTime = nowDate.getTime();
long birTime = date.getTime();
return (nowDateTime - birTime) / (1000 * 60 * 60 * 24) / 365;
}
private void above60() throws ParseException {
if (mgrLogIndex) {
for (int i = 0; i < people.length; i++) {
if (people[i] != null && getAge(people[i].getBirthday()) > 60) {
System.out.println(people[i]);
}
}
}
}
private void showDifVip() {
int xin = 0;
int yue = 0;
int sun = 0;
for (int i = 0; i < people.length; i++) {
if (people[i] != null && people[i].getJifen() >= 0 && people[i].getJifen() < 100) {
System.out.println("⭐" + people[i]);
xin++;
} else if (people[i] != null && people[i].getJifen() < 1000) {
System.out.println("uD83CuDF19" + people[i]);
yue++;
} else if (people[i] != null) {
System.out.println("☀" + people[i]);
sun++;
}
}
System.out.println("⭐等级有:" + xin);
System.out.println("uD83CuDF19等级有:" + yue);
System.out.println("☀等级有:" + sun);
}
private void changeStatus() {
System.out.print("请输入需要修改状态的手机尾号:");
String tel = sc.next();
String regex = "(\d{3})(\d{4})(\d{4})";
String replace = tel.replaceAll(regex, "$3");
for (int i = 0; i < people.length; i++) {
if (people[i] != null && replace.equals(tel)) {
System.out.println("修改前:" + people[i]);
System.out.println("请输入需要修改的状态:(0或1)");
int stats = sc.nextInt();
people[i].setStatus(stats);
System.out.println("修改后:" + people[i]);
System.out.println("修改成功!");
break;
} else {
System.out.println("没有找到该号码!");
}
}
}
}
这是主类写的比较多;
public class Admin extends Person{
private int aid;
private String name;
private String password;
public Admin() {
}
public Admin(int aid, String name, String password) {
this.aid = aid;
this.name = name;
this.password = password;
}
public int getAid() {
return aid;
}
public void setAid(int aid) {
this.aid = aid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void shwoMenu(Admin admin) {
System.out.println("-----------欢迎您,【" + admin.getName() + "】----------");
System.out.println("t1,添加会员");
System.out.println("t2,查看所有会员信息");
System.out.println("t3,查看年龄30岁以下的会员信息");
System.out.println("t4,查看年龄60岁以上的会员信息");
System.out.println("t5,统计不同等级的会员人数");
System.out.println("t6,会员状态变更");
System.out.println("t7,退出");
}
}
这是管理员类;
这里我用管理员类继承了person类但是不知道能不呢继承我person类中重写的toString方法就只有显示菜单栏的一个方法传的是一个Admin对象可以获取admin的姓名
public class Person {
private int pid;
private String name;
private String password;
private String address;
private String phone;
private String birthday;
private int jifen;
private double money;
private int status;
public void showMenu(Person person) {
System.out.println("-----------欢迎您,【" + person.getName() + "】----------");
System.out.println("t1,查看信息");
System.out.println("t2,充值");
System.out.println("t3,修改密码");
System.out.println("t4,参加积分换购活动");
System.out.println("t5,退出");
}
public void showAll(Person person) {
if (person.getJifen()<100 && person.getJifen()>=0) { System.out.print("⭐"); }
else if (person.getJifen()<1000) { System.out.println(" uD83CuDF19"); }
else { System.out.println("uD83CuDF19" + " (可以参加换购活动)"); }
if (person.getMoney()<=20) System.out.println("您的余额还剩" +person.getMoney() + "!请及时充值");
System.out.print("姓名:" + person.getName() + " ");
System.out.print("密码:" +person.getPassword()+ " ");
System.out.print("地址:" +person.getAddress()+ " ");
System.out.print("pid:" +person.getPid()+ " ");
System.out.print("生日:" +person.getBirthday()+ " ");
System.out.print("积分:" +person.getJifen()+ " ");
System.out.print("电话:" +person.getPhone()+ " ");
System.out.print("余额:" +person.getMoney()+ " ");
System.out.print("状态:" +person.getStatus()+ "n");
}
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public int getJifen() {
return jifen;
}
public void setJifen(int jifen) {
this.jifen = jifen;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public Person() {
}
public Person(int pid, String name, String password, String address, String phone, String birthday, int jifen, double money, int status) {
this.pid = pid;
this.name = name;
this.password = password;
this.address = address;
this.phone = phone;
this.birthday = birthday;
this.jifen = jifen;
this.money = money;
this.status = status;
}
@Override
public String toString() {
return "客户信息:" +
"pid=" + pid +
", 姓名='" + name + ''' +
", 密码='" + password + ''' +
", 地址='" + address + ''' +
", 手机='" + phone + ''' +
", 生日='" + birthday + ''' +
", 积分=" + jifen +
", 余额=" + money +
", 状态=" + status +
'}';
}
}
这是我写的person类重写了toString方法(应该说是自动生成的哈哈哈)
ps:想使用的话直接创建三个和我一样的类名一定要一样,然后直接复制进去就好了,点main方法运行可以测试我所写的项目啦!



