/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package startbank;
import com.bank.entity.Bank;
import com.bank.entity.BankCard;
import com.bank.management.BankBusiness;
import java.io.IOException;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class Main {
public static void main(String args[]) {
Bank b = new Bank("001", "中国银行");
BankBusiness bankBuz = new BankBusiness();
while (true) {
int num = 1;
System.out.println("***************银行系统*******************");
System.out.println("* *");
System.out.println("* 1 申请银行卡 *");
System.out.println("* *");
System.out.println("* 2 ATM机服务 *");
System.out.println("* *");
System.out.println("* 3 退出系统 *");
System.out.println("* *");
System.out.println("****************************************");
System.out.println();
System.out.println("请选择您的服务:");
Scanner read = new Scanner(System.in);
try {
num = read.nextInt();
} catch (Exception ex) {
System.out.println("对不起,输入错误!");
}
if (num == 1) {
bankCardService(bankBuz);//银行卡服务
} else if (num == 2) {
atmServices(bankBuz);//ATM服务
} else if (num == 3) {
System.out.println("退出系统!欢迎下次使用!");
System.exit(0);
} else {
System.out.println("对不起,输入错误!");
}
}
}
private static void bankCardService(BankBusiness bankBuz) {
Scanner read = new Scanner(System.in);
System.out.println("******************申请银行卡******************");
System.out.println("");
System.out.println("请输入姓名:");
String name = read.next();
System.out.println("请输入身份证号码:");
String PID = read.next();
System.out.println("请输入密码:");
String pwd = read.next();
System.out.println("请输入联系电话:");
String telephone = read.next();
System.out.println("请输入家庭住址:");
String address = read.next();
System.out.println();
BankCard card = bankBuz.sendCard(name, PID, telephone, address, pwd);
System.out.println(">>>>>>>>>>>>>>>恭喜您申请成功<<<<<<<<<<<<<<<");
System.out.println("你的卡号为: " + card.getCardID());
System.out.println("你的姓名为: " + card.getAccoutName());
System.out.println("你的密码为: " + card.getPassword());
System.out.println("你的金额为: " + String.valueOf(card.getBalance()) + " 元");
//bankBuz.getAllBankCardInfo();//用于测试帐户是否申请成功
}
private static void atmServices(BankBusiness bankBuzb) {
System.out.println("******************ATM系统******************");
System.out.println();
for (int i = 3; i >= 1; i--) {
System.out.print("请输入你的银行卡号:");
Scanner input = new Scanner(System.in);
String cardid = input.next();
System.out.print("请输入密码:");
input = new Scanner(System.in);
String psw = input.next();
BankCard sCard = bankBuzb.searchForCardID(cardid);//查找
if (sCard != null && psw.equals(sCard.getPassword())) {
System.out.println("-------登录成功! 转入ATM子服务!--------");
atmSubServices(bankBuzb, sCard);
break;
} else if (i != 1) {
System.out.println("\\n卡号和密码不匹配!你还剩下" + (i - 1) + " 次机会!");
//超过3次输入,退出
System.out.println("请重新输入: ");
} else {
System.out.println("\\n您没有权限进入系统!系统退出!");
System.exit(0);
}
}
}
private static void atmSubServices(BankBusiness bankBuz, BankCard card) {
while (true) {
System.out.println("***************ATM系统*******************");
System.out.println("* *");
System.out.println("* 1 查询余额 *");
System.out.println("* *");
System.out.println("* 2 存钱 *");
System.out.println("* *");
System.out.println("* 3 取钱 *");
System.out.println("* *");
System.out.println("* 4 转帐 *");
System.out.println("* *");
System.out.println("* 5 修改密码 *");
System.out.println("* * ");
System.out.println("* 6 返回主界面 *");
System.out.println("* * ");
System.out.println("**************************************");
System.out.println();
System.out.print("请选择你的服务:");
Scanner read = new Scanner(System.in);
int select = 1;
try {
select = read.nextInt();
} catch (Exception ex) {
System.out.println("输入格式错误!");
break;
}
switch (select) {
case 1:
System.out.println(card.getCardID());
System.out.print("你的余额是: ");
System.out.println(bankBuz.queryCash(card) + "元");
System.out.print("(返回请按Enter): ");
try {
System.in.read();
} catch (IOException ex) {
}
break;
case 2:
System.out.print("请输入你的存款金额: ");
double moneyin = read.nextDouble();
System.out.println(bankBuz.saveCash(card, moneyin));
try {
System.in.read();
} catch (IOException ex) {
}
break;
case 3:
System.out.print("请输入你的取款金额: ");
double moneyout = read.nextDouble();
System.out.println(bankBuz.withdraw(card, moneyout));
try {
System.in.read();
} catch (IOException ex) {
}
break;
case 4:
System.out.print("请输入你需转账的卡号: ");
String acceptercardid = read.next();
System.out.print("请输入你需要转账的金额: ");
double money = read.nextDouble();
System.out.println(bankBuz.transfer(card, acceptercardid, money));
try {
System.in.read();
} catch (IOException ex) {
}
break;
case 5:
System.out.print("请输入你需要修改的密码: ");
String newpwd = read.next();
Sy