java 模拟一个ATM系统: 1. 内置一个管理员账户: admin admin
2021/9/29 11:10:55
本文主要是介绍java 模拟一个ATM系统: 1. 内置一个管理员账户: admin admin,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] user_cards = new int[1];
int[] user_pwd = new int[1];
int[] user_balance = new int[1];
boolean[] user_status = new boolean[1];
String name = "", pwd = "", other_account = "", other_balance;
int len = 1;
int index;
boolean flag_1 = false;
// 持续在线
flag2: while (true) {
System.out.println("\n\n\n----------------欢迎使用ATM自助系统----------------");
System.out.print("请输入账号:");
name = scanner.next();
if (name.equals("admin")) {
System.out.print("请输入密码:");
pwd = scanner.next();
if (pwd.equals("admin")) {
System.out.println("\r-----登录成功,亲爱的管理员 " + name + " 欢迎您-----\r");
flag3: for (;;) {
System.out.println(
"-------------------\r" + "\t1 开卡\r\n" + "\t2 注销卡\r\n" + "\t3 查看所有用户列表(可以查看单个用户)\r\n"
+ "\t4 冻结用户\r\n" + "\t5 切换用户\r\n" + "\t6 退出系统\r" + "-------------------");
System.out.print("请输入您的选择:");
int operation = scanner.nextInt();
switch (operation) {
// 开卡
case 1:
if (flag_1 == true) {
user_cards = Arrays.copyOf(user_cards, len + 1);
user_pwd = Arrays.copyOf(user_pwd, len + 1);
user_status = Arrays.copyOf(user_status, len + 1);
user_balance = Arrays.copyOf(user_balance, len + 1);
}
len = user_cards.length;
user_cards[len - 1] = 1000 + len;
System.out.print("新开卡号为:" + user_cards[len - 1]);
user_status[len - 1] = true;
user_balance[len - 1] = 0;
flag_1 = true;
System.out.print("\t请设置密码:");
user_pwd[len - 1] = scanner.nextInt();
System.out.println("设置成功,密码为:" + user_pwd[len - 1] + "\r\r");
break;
// 注销卡
case 2:
if (user_cards.length == 1 && user_cards[0] == 0) {
System.out.println("当前账户为空,请先开户!");
break;
}
for (int i = 0; i < user_cards.length; i++) {
System.out.print("账号:" + user_cards[i] + "\t");
System.out.print("密码:" + user_pwd[i] + "\t");
System.out.print("余额:" + user_balance[i] + "\t");
if (user_status[i]) {
System.out.println("状态:启用中");
} else {
System.out.println("状态:已停用");
}
}
System.out.print("输入需要删除的账户: ");
name = scanner.next();
for (int j = 0; j < user_cards.length; j++) {
if (name.equals(Integer.toString(user_cards[j]))) {
System.out.println("是否删除该账户?\r\t1.确定\r\t2.取消");
int select = scanner.nextInt();
switch (select) {
case 1:
for (int k = 0; k < user_cards.length; k++) {
if (name.equals(Integer.toString(user_cards[k]))) {
index = k;
if (k < user_cards.length) {
for (int l = k; l < user_cards.length - 1; l++) {
user_cards[l] = user_cards[l + 1];
user_pwd[l] = user_pwd[l + 1];
user_status[l] = user_status[l + 1];
user_balance[l] = user_balance[l + 1];
}
user_cards = Arrays.copyOf(user_cards, user_cards.length - 1);
user_pwd = Arrays.copyOf(user_pwd, user_pwd.length - 1);
user_status = Arrays.copyOf(user_status, user_status.length - 1);
user_balance = Arrays.copyOf(user_balance, user_balance.length - 1);
System.out.println("删除成功");
continue flag3;
}
}
}
}
}
break flag3;
}
// 查看所有用户列表
case 3:
for (int i = 0; i < user_cards.length; i++) {
if (!name.equals(Integer.toString(user_cards[i]))) {
System.out.println("账号不存在!请检查后从新输入!\r\r");
}
break;
}
if (user_cards.length == 1 && user_cards[0] == 0) {
System.out.print("当前账户为空,请先开户!\r\r\r");
break;
}
for (int i = 0; i < user_cards.length; i++) {
System.out.print("账号:" + user_cards[i] + "\t");
System.out.print("密码:" + user_pwd[i] + "\t");
System.out.print("余额:" + user_balance[i] + "\t");
if (user_status[i]) {
System.out.print("状态: 启用中\r");
} else {
System.out.print("状态: 已停用\r");
}
}
System.out.println("");
break;
// 冻结用户
case 4:
for (int i = 0; i < user_cards.length; i++) {
System.out.print("账号:" + user_cards[i] + "\t");
System.out.print("密码:" + user_pwd[i] + "\t");
System.out.print("余额:" + user_balance[i] + "\t");
if (user_status[i]) {
System.out.println("状态: 启用中");
} else {
System.out.println("状态: 已停用");
}
}
System.out.print("输入需要冻结的账户:");
name = scanner.next();
// 处理输入不正确
for (int i = 0; i < user_cards.length; i++) {
if (!name.equals(Integer.toString(user_cards[i]))) {
System.out.println("账号不存在!请检查后从新输入!\r\r");
}
break;
}
flag1: for (int i = 0; i < user_cards.length; i++) {
if (name.equals(Integer.toString(user_cards[i]))) {
System.out.println("是否停用该账户?\r\t1.停用\r\t2.启用");
int select = scanner.nextInt();
switch (select) {
case 1:
user_status[i] = false;
System.out.println("\t停用成功\r");
break;
case 2:
user_status[i] = true;
System.out.println("\t启用成功\r");
break;
default:
System.out.println("输入有误请从新输入!\r\r\r");
break;
}
}
}
break;
// 切换用户
case 5:
System.out.println("退出成功!欢迎再次使用!\r\r\r");
continue flag2;
// 退出系统
case 6:
System.out.println("退出成功!欢迎再次使用!\r\r\r");
break flag2;
default:
System.out.println("输入有误请从新输入!\r\r\r");
break;
}
}
} else {
System.out.println("密码错误请检查后从新输入!\r\r\r");
continue;
}
} else {
// 处理没有账户时提示
for (int i = 0; i < user_cards.length; i++) {
if (!name.equals(Integer.toString(user_cards[i]))) {
System.out.println("账号不存在!请检查后从新输入!\r\r");
}
break;
}
for (int f = 0; f < user_cards.length; f++) {
if (name.equals(Integer.toString(user_cards[f]))) {
if (user_status[f] == false) {
System.out.println("您的账户被停用,请联系管理员处理!");
break;
}
} else {
continue;
}
flag: for (int i = 0; i < user_cards.length; i++) {
System.out.print("请输入密码:");
pwd = scanner.next();
if (pwd.equals(Integer.toString(user_pwd[i]))) {
System.out.print("登录成功, " + user_cards[i] + " 欢迎您");
for (;;) {
System.out
.println("-------------------\r" + "\t1 查看余额\r\n" + "\t2 转账\r\n" + "\t3 取钱\r\n"
+ "\t4 存钱\r\n" + "\t5 切换用户\r\n" + "\t6 退出系统\r" + "-------------------");
System.out.print("请输入您的选择: ");
int operation = scanner.nextInt();
switch (operation) {
// 查看余额
case 1:
for (int z = 0; z < user_cards.length; z++) {
if (name.equals(Integer.toString(user_cards[z]))) {
System.out.println("您的余额为:" + user_balance[z] + "元");
}
}
break;
// 转账
case 2:
System.out.print("请输入对方账号: ");
other_account = scanner.next();
if (name.equals(other_account)) {
System.out.println("不能给自己转账!请重新选择操作!\r\r\r");
break;
}
for (int z = 0; z < user_cards.length; z++) {
if (other_account.equals(Integer.toString(user_cards[z]))) {
System.out.print("请输入转账金额: ");
other_balance = scanner.next();
if (Integer.parseInt(other_balance) <= user_balance[z]) {
user_balance[z] -= Integer.parseInt(other_balance);
System.out.println("转账成功您的当前余额为: " + user_balance[z] + " 元");
} else {
System.out.println("余额不足!\r\r\r");
}
} else {
System.out.println("对方账户不存在!请检查后从新输入!\r\r\r");
break;
}
}
break flag;
// 取钱
case 3:
for (int z = 0; z < user_cards.length; z++) {
System.out.println("请输入取款金额:");
other_balance = scanner.next();
if (Integer.parseInt(other_balance) <= user_balance[z]) {
user_balance[z] -= Integer.parseInt(other_balance);
System.out.println("取款成功您的当前余额为:" + user_balance[z] + "元");
} else {
System.out.println("余额不足!\r\r\r");
}
}
break;
// 4 存钱
case 4:
for (int z = 0; z < user_cards.length; z++) {
if (name.equals(Integer.toString(user_cards[z]))) {
System.out.print("请放置存入的纸币!");
other_balance = scanner.next();
user_balance[z] += Integer.parseInt(other_balance);
System.out.println("存入成功:" + other_balance + "元");
System.out.println("您当前余额为:" + user_balance[z] + "元\r\r\r");
}
}
break;
// 切换用户
case 5:
System.out.println("退出成功!欢迎再次使用!\r\r\r");
continue flag2;
// 退出系统
case 6:
System.out.println("退出成功!欢迎再次使用!\r\r\r");
break flag2;
default:
System.out.println("输入有误请从新输入!\r\r");
break;
}
}
} else {
System.out.println("密码错误请检查后从新输入!");
break;
}
}
}
}
}
}
这篇关于java 模拟一个ATM系统: 1. 内置一个管理员账户: admin admin的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南