package testATM;
import java.util.Scanner;
public class Operation {
private int f = 0;
Services ser;
public Operation(){
ser = new Services();
}
Scanner scan = new Scanner(System.in);
public void login() {
System.out.println("1、进入系统\t2、退出");
int i1 = scan.nextInt();
boolean flag = true;
while (flag) {
switch (i1) {
case 1:
// welcome();
flag = false;
break;
case 2:
rewelcome();
System.exit(0);
default:
System.out.println("请重新输入:");
i1 = scan.nextInt();
}
}
System.out.println("请输入密码:");
String pw = scan.next();
while (ser.getT() < 2) {
if (ser.getPassword().equals(pw)) {
ser.setT(0);
break;
} else {
System.out.println("密码错误,请重新输入");
ser.setT(ser.getT() + 1);
pw = scan.next();
}
}
if (ser.getT() == 2) {
System.out.println("由于输入的次数过多,您的卡已经被ATM吞掉,请联系工作人员!");
System.exit(0);
}
System.out.println("选择服务语言:1 中文\t2 英文");
flag = true;
while (flag) {
int i2 = scan.nextInt();
switch (i2) {
case 1:
flag = false;
break;
case 2:
System.out.println("英文系统正在建设中。。。");
System.out.println("选择服务语言:1 中文\t2 英文");
break;
default:
System.out.println("请输入1或2");
}
}
}
public void serviceAll() {
boolean flag = true;
while (flag) {
service();
String i3 = scan.next();
while (ser.getT() < 2) {
if ("1".equals(i3)) {
System.out.println("账户余额为" + ser.getBalance() + "元");
ser.setT(0);
break;
} else if (i3.equals("2")) {
ser.setT(0);
flag = false;
f = 2;
// System.out.println(this.f);
draw();
break;
} else if (i3.equals("3")) {
ser.setT(0);
flag = false;
f = 3;
trans();
break;
} else if (i3.equals("4")) {
ser.setT(0);
flag = false;
f = 4;
deposit();
break;
} else if (i3.equals("5")) {
rewelcome();
ser.setT(0);
System.exit(0);
} else {
System.out.println("服务项目不存在,请重新选择服务项目!");
ser.setT(ser.getT() + 1);
i3 = scan.next();
}
}
if (ser.getT() == 2) {
System.out.println("不要捣乱了,赶紧回家吧!");
rewelcome();
System.exit(0);
}
}
}
public void deposit() {
System.out.println("1)提示该ATM机一次能存款的最大金额为10000元.");
System.out.println("2)用户的帐户一天存款累计的最大金额为50000元.");
System.out.println("请输入存款金额:");
int balance = 0;
while (true) {
balance = scan.nextInt();
if (ser.getDepositAll() + balance > 50000) {
System.out.println("用户的帐户一天存款累计的最大金额为50000元,您已存款"
+ ser.getDepositAll() + "元");
service2();
} else {
if (balance % 50 != 0) {
System.out.println("输入有误,存款金额必须为50的整数倍.");
service2();
} else if (balance > 10000) {
System.out.println("存款额度最大限度为10000.输入有误.");
service2();
} else {
ser.setBalance(ser.getBalance() + balance);
ser.setDepositAll(ser.getDepositAll() + balance);
break;
}
}
}
service1();
}
public void trans() {
while (true) {
System.out.println("请输入转入账户");
String str = scan.next();
if (check(str)) {
System.out.println("请确认转入账户");
String str1 = scan.next();
if (str.equals(str1)) {
System.out.println("转账一次的金额不能超过10000元,请您输入转账金额");
int balance = scan.nextInt();
if (check(String.valueOf(balance)) && balance >= 1
&& balance <= 10000) {
if (balance > ser.getBalance()) {
System.out.println("余额不足");
service2();
} else {
ser.setBalance(ser.getBalance() - balance);
break;
}
} else {
System.out.println("转账金额必须全是数字,并且在1-10000之间");
service2();
}
} else {
System.out.println("前后账号要一致");
service2();
}
} else {
System.out.println("账户必须全都是数字");
service2();
}
}
service1();
}
public void draw() {
boolean flag = true;
service3();
int a = 0;
int i5 = scan.nextInt();
while (flag) {
int balance = 0;
switch (i5) {
case 1:
balance = 500;
break;
case 2:
balance = 1000;
break;
case 3:
balance = 2000;
break;
case 4:
if (a == 0) {
System.out.println("请输入取款金额(只能输入100的整数倍,并且要小于2000):");
balance = scan.nextInt();
}
while (true) {
if (checkBalance(balance)) {
ser.setBalance(ser.getBalance() - balance);
ser.setDrawAll(balance + ser.getDrawAll());
service1();
flag = false;
break;
} else {
service2();
flag = true;
balance = scan.nextInt();
}
}
break;
default:
System.out.println("输入错误.");
service2();
}
if (flag) {
if (checkBalance(balance)) {
ser.setBalance(ser.getBalance() - balance);
ser.setDrawAll(balance + ser.getDrawAll());
service1();
flag = false;
} else {
service2();
flag = true;
balance = scan.nextInt();
i5 = 4;
a = 1;
}
}
}
}
public boolean check(String str) {
boolean flag = true;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) < 48 || str.charAt(i) > 58) {
flag = false;
break;
}
}
if (flag)
return true;
else
return false;
}
public boolean checkBalance(
int balance) {
boolean flag = true;
if (balance > ser.getBalance()) {
System.out.println("余额不足");
flag = false;
} else if (balance > 2000) {
System.out.println("请输入2000以下的整数");
flag = false;
} else if (ser.getDrawAll() == 5000) {
System.out.println("您今日取款已达到限制,请选择其他项目或去柜台取钱");
flag = false;
} else if (ser.getDrawAll() + balance > 5000) {
System.out.println("用户的帐户一天取款累计的最大金额为5000元,今日累计取款"
+ ser.getDrawAll());
flag = false;
} else if (balance % 100 != 0) {
System.out.println("请输入100的整数倍");
flag = false;
} else
flag = true;
if (flag)
return true;
else
return false;
}
public void service2() {
System.out.println("1.重新输入\t2.退出系统");
System.out.println("");
while (true) {
int i6 = scan.nextInt();
if (i6 == 2) {
rewelcome();
System.exit(0);
} else if (i6 == 1) {
break;
} else
System.out.println("请重新输入");
}
}
public void service3() {
System.out.println("1)提示该ATM机一次能取款的最大金额为2000元.");
System.out.println("2)用户的帐户一天取款累计的最大金额为5000元.");
System.out
.println("-----------------请选择取款金额----------------------");
System.out.println(" 1. 500 2. 1000 3. 2000 4. 其他金额");
System.out.println("");
}
public void service() {
System.out.println("-------------------请选择服务项目-------------------");
System.out.println(" 1. 查询余额 2. 取款 3. 转账 4. 存款 5. 退出");
System.out.println("");
}
public void service1() {
System.out.println("服务完成,请选择:1. 继续服务 2.主页面 3.退出");
System.out.println("");
boolean flag=true;
while (flag) {
int i4 = scan.nextInt();
if (i4 == 1) {
// System.out.println(this.f);
if (f == 2) {
System.out.println(f);
draw();
flag=false;
} else if (f == 3) {
System.out.println(f);
trans();
flag=false;
} else if (f == 4) {
System.out.println(f);
deposit();
flag=false;
}
}
else if (i4 == 2) {
serviceAll();
f = 0;
flag=false;
} else if (i4 == 3) {
rewelcome();
System.exit(0);
} else {
System.out.println("输入错误,请重新输入");
}
}
}
public void welcome() {
System.out
.println("-----------------------------------------------------------");
System.out
.println("----------------------欢迎使用xxxx银行ATM系统--------------------");
System.out
.println("-----------------------------------------------------------");
System.out.println("");
}
public void rewelcome() {
System.out
.println("-----------------------------------------------------------");
System.out
.println("------------------欢迎再次使用xxxx银行ATM系统,再见!----------------");
System.out
.println("-----------------------------------------------------------");
System.out.println("");
}
}