package com.huizhong;
import java.util.Random;
import java.util.Scanner;
public class ATM {
// int cardNumo=0;
String pwd;
Users users=new Users();
// String s;
// static int count = 21;
String[] storeUsers=new String[4];
Scanner scanner = new Scanner(System.in);
public void mainFrame() {
System.out.println("===========================");
System.out.println(" 欢迎进入ATM自助系统 ");
System.out.println("1.开户");
System.out.println("2.插卡");
System.out.println("3.系统管理");
System.out.println("请选择菜单:");
int choice = scanner.nextInt();
switch (choice) {
case 1:
this.start();
break;
case 2:
this.insertCard();
break;
case 3:
this.SystemManage();
break;
default:System.out.println("请在1-3内进行选择:");
break;
}
}
public void start() {
boolean flag = true;
Random rd = new Random();
int cardNum0 = rd.nextInt(9999)*10000;
System.out.println("系统为你生成的卡号为:" + cardNum0);
users.cardNum0[0]=""+cardNum0;
users.cardNum0[1]=""+(cardNum0+1);
users.cardNum0[2]=""+(cardNum0+2);
users.cardNum0[3]=""+(cardNum0+3);
while (flag) {
System.out.println("请输入密码:");
String pwd = scanner.next();
System.out.println("请确认输入密码:");
String pwd1 = scanner.next();
if (!(pwd.equals(pwd1))) {
System.out.println("你的两次输入密码不一致请重新输入");
continue;
} else {
users.pwd[0] = pwd;
System.out.println("开户成功!是否存款 ?(Y/N)");
String choice1 = scanner.next();
if (choice1.toUpperCase().equals("Y")) {
boolean flag2 = true;
while (flag2) {
System.out.print("请输入金额>>");
float money = scanner.nextFloat();
if (money < 0) {
System.out.print("金额不能为负数,请重新输入!");
continue;
}
System.out.println("存款成功!");
users.money[0] = money;
flag2 = false;
}
flag2 = false;
} else {
flag = false;mainFrame();
break;
}
System.out.println();
System.out.println("您的当前信息是");
System.out.println("卡号:" + users.cardNum0[0] + " " + "密码:"
+ users.pwd[0] + " " + "余额:" + users.money[0] + "元");
}
flag = false;
mainFrame();break;
}
flag = false;
}
public void SystemManage() {
boolean flag1=true;
while (flag1) {
System.out.println("1. 查看所有用户");
System.out.println("2. 冻结用户");
System.out.println("3. 恢复用户");
System.out.println("4. 退出系统");
System.out.println("请选择菜单:");
int choice1 = scanner.nextInt();
switch (choice1) {
case 1:
this.SlestAllUsers();
break;
case 2:
this.frozen();
break;
case 3:
this.recover();
break;
case 4:
this.over();
flag1=false;
break;
default:System.out.println("请在1-4里进行选择:");
break;
}
}
}
public void SlestAllUsers() {
for (int i = 0; i < 4; i++) {
System.out.println("所有用户信息:" + users.cardNum0[i]);
}
}
public void frozen(){
System.out.println("请输入你要冻结的账号:");
String fstr=scanner.next();
for(int i=0;i<4;i++){
if(!(fstr.equals(users.cardNum0[i]))){
//System.out.println("你所要冻结的账号不存在:");
continue;
}
System.out.println("冻结成功!");
users.pwd[i]="222";
storeUsers[i]=users.cardNum0[i];
break;
}
}
public void recover(){
System.out.println("请输入你的账号:");
String rstr=scanner.next();
for(int i=0;i<4;i++){
if(!(rstr.equals(storeUsers[i]))){
//System.out.println("你的账号可以正常运行");
continue;
}
System.out.println("对不起,你的账号已被冻结,请先激活");
System.out.println("请输入你的密码");
String rpwd=scanner.next();
if(!(rpwd.equals(users.pwd[i]))){
System.out.println("你输入的密码有错,激活不成功");continue;
}else{
System.out.println("激活成功");break;
}
}
}
public void over(){
System.out.println("你还需要继续交易吗 Y / N");
String choice4 = scanner.next();
if (choice4.toUpperCase().equals("Y")) {
mainFrame();
}
if (choice4.toUpperCase().equals("N")) {
System.out.println("谢谢你的使用!!!!!");
}
}
public void insertCard() {
boolean flag4=true;
while (flag4) {
System.out.println("请输入你的卡号:");
String str = scanner.next();
System.out.println("请输入你的密码:");
String s2 = scanner.next();
if (!(str.equals(users.cardNum0[0]) && s2.equals(users.pwd[0]))) {
System.out.println("你输入的账号或密码有错,请重新输入");
} else {
System.out.println("登陆成功!");showMoneyFrame();break;
}
}
flag4=false;
}
public void showMoneyFrame(){
boolean flag5=true;
while(flag5){
System.out.println("欢迎登陆取款系统!!!");
System.out.println("1. 查看余额");
System.out.println("2. 存款");
System.out.println("3. 转账");
System.out.println("4. 退出系统");
System.out.println("请选择你的交易类型:");
int choice2=scanner.nextInt();
// boolean flag3=true;
// while(flag3){
/**
* if(choice2==1){ System.out.println("你当前的余额为"+users.money[0]); }
* System.out.println("请选择你的交易类型:"); choice2=scanner.nextInt();
* if(choice2==2){ System.out.println("请输入你的存款金额"); //} float
* money=scanner.nextFloat(); if(money<0){
* System.out.println("存款金额不能为负数,请重新输入:"); }
* System.out.println("存款成功!!!");
* users.money[0]=money+users.money[0]; }
* System.out.println("请选择你的交易类型:"); choice2=scanner.nextInt();
* if(choice2==3){ System.out.println("请输入你的转账账号:"); String
* str=scanner.next(); for(int i=0;i<4;i++){
* if(str.equals(users.cardNum0[i])){ boolean flag4=true;
* while(true){ System.out.print("请输入转账金额:"); float
* trMoney=scanner.nextFloat(); if((users.money[0]-trMoney)<0){
* System.out.println("对不起,您的账户金额不足!");break; } if(trMoney<0){
* System.out.println("金额不能为负数,请重新输入!");continue; }
* System.out.println("转账完成!");
* users.money[i]=users.money[i]+trMoney;
* users.money[0]=users.money[0]-trMoney;flag4=false;break; }
* flag4=false; } } } if(choice2==4){
* System.out.println("退出系统");mainFrame();break; }
*/
switch(choice2){
case 1:
System.out.println("你当前的余额为"+users.money[0]);break;
// System.out.println("请选择你的交易类型:");
// choice2=scanner.nextInt();
// if(choice2==2){
case 2: System.out.println("请输入你的存款金额");
// }
float money=scanner.nextFloat();
if(money<0){
System.out.println("存款金额不能为负数,请重新输入:");
}
System.out.println("存款成功!!!");
users.money[0]=money+users.money[0];break;
// }
// System.out.println("请选择你的交易类型:");
// choice2=scanner.nextInt();
case 3:System.out.println("请输入你的转账账号:");
String str=scanner.next();
for(int i=0;i<4;i++){
if(str.equals(users.cardNum0[i])){
boolean flag4=true;
while(true){
System.out.print("请输入转账金额:");
float trMoney=scanner.nextFloat();
if((users.money[0]-trMoney)<0){
System.out.println("对不起,您的账户金额不足!");break;
}
if(trMoney<0){
System.out.println("金额不能为负数,请重新输入!");continue;
}
System.out.println("转账完成!");
users.money[i]=users.money[i]+trMoney;
users.money[0]=users.money[0]-trMoney;flag4=false;break;
}
flag4=false;
}
}
case 4:System.out.println("退出系统");mainFrame();break;
default:System.out.println("请在1-4内选择:");
}
}
flag5=false;
}
public static void main(String[] args){
ATM atm=new ATM();
atm.mainFrame();
atm.insertCard();
}
}