package com.fzyun;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class ATMSystem {
public static void main(String[] args) {
ArrayList<Account> accounts = new ArrayList<>();
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("==========ATM系统==========");
System.out.println("1:账户登录");
System.out.println("2:用户注册");
System.out.println("请您选择数字进行操作");
int command = sc.nextInt();
switch (command){
case 1:
login(accounts, sc);
break;
case 2:
register(accounts,sc);
break;
default:
System.out.println("您输入的操作命令不存在");
}
}
}
private static void login(ArrayList<Account> accounts, Scanner sc) {
System.out.println("========系统登陆操作=======");
if (accounts.size() == 0){
System.out.println("对不起,此系统还没有任何账户,请先注册");
return;
}
while (true) {
System.out.println("请您输入登陆卡号:");
String cardID = sc.next();
Account acc = getAccountByCardID(cardID , accounts);
if (acc != null){
while (true) {
System.out.println("请您输入密码:");
String passWord = sc.next();
if (acc.getPassWord().equals(passWord)){
System.out.println(acc.getUserName() + "登陆成功" + "您的卡号是" + acc.getCardID());
showUserCommand(sc , acc);
}else {
System.out.println("您输入的密码有误");
}
}
}else {
System.out.println("系统中不存在该账户卡号q");
}
}
}
private static void showUserCommand(Scanner sc , Account acc) {
while (true) {
System.out.println("========用户操作页=======");
System.out.println("1.查询账户");
System.out.println("1.存款");
System.out.println("1.取款");
System.out.println("1.转账");
System.out.println("1.修改密码");
System.out.println("1.退出");
System.out.println("1.注销账户");
System.out.println("请选择:");
int command = sc.nextInt();
switch (command){
case 1:
showAccount(acc);
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
default:
System.out.println("您输入的操作命令不争取");
}
}
}
private static void register(ArrayList<Account> accounts,Scanner sc) {
System.out.println("=======系统注册界面========");
Account account = new Account();
System.out.println("请您输入账户名称:");
String userName = sc.next();
account.setUserName(userName);
while (true) {
System.out.println("请您输入密码:");
String passWord = sc.next();
System.out.println("请您再次确认密码:");
String okPassWord = sc.next();
if (okPassWord.equals(passWord)){
account.setPassWord(okPassWord);
break;
}else {
System.out.println("您输入的两次密码不一致,请重新确认");
}
}
System.out.println("请您输入账户当次限额:");
double quotaMoney = sc.nextDouble();
account.setQuotaMoney(quotaMoney);
String carID = getRandomCardID(account);
account.setCardID(carID);
account.add(account);
System.out.println("恭喜您" + userName + "注册成功" + "请您妥善保管卡号");
}
private static String getRandomCardID(ArrayList<Account> accounts) {
Random r = new Random();
while (true) {
String cardID = "";
for (int i = 0; i < 8; i++) {
cardID += r.nextInt(10);
}
Account acc = getAccountByCardID(cardID,accounts);
if (acc == null){
return cardID;
}
}
}
private static Account getAccountByCardID(String cardID , ArrayList<Account> accound){
for (int i = 0; i < accound.size(); i++) {
Account acc = accound.get(i);
if (acc.getCardID().equals(cardID)){
return acc;
}
}
return null;
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏