package homework.bank;
import java.util.Scanner;
/**
* 测试
*
* @auther Teacher
* @Date Aug 26, 2009
*/
public class TestBank {
public static void main(String[] args) throws Exception {
Bank bank = new Bank("中国银行");
Scanner sc = new Scanner(System.in);
int type = 0;
Account account = null;
while (true) {
System.out.println(" 欢迎使用 " + bank + " 后台管理系统"
+ "\n1:注册 2:登录 3:退出");
String input = sc.next();
if ("1".equals(input)) {
System.out.println("请输入要注册的银行卡类型1 or 2 >> 1:借记卡 2:信用卡");
input = sc.next();
String[] acc = new String[2];
if ("1".equals(input)) {
type = 0;
account = (DebitAccount) getAccount(type);
} else if ("2".equals(input)) {
type = 1;
account = (CreditAccount) getAccount(type);
} else {
continue;
}
bank.register(account);
System.out.println("新账户为: 卡号" + account);
System.out.println("-----------本行所有账户--------------");
bank.printAll();
} else if ("2".equals(input)) {
Account acc2 = null;
for (;;) {
System.out.println("请输入卡号:");
String idStr = sc.next();
long id = 0;
try {
id = Long.parseLong(idStr);
} catch (NumberFormatException e) {
System.out.println("卡号为数字类型,请输入数字!!");
continue;
}
System.out.println("请输入密码:");
String password = sc.next();
acc2 = bank.login(id, password);
if (acc2 == null) {
continue;
} else {
break;
}
}
for (;;) {
System.out.println(" 欢迎 " + acc2.getName()
+ " 使用银行管理系统" + "\n1:取款 2:存款 3:查询余额 4:修改密码 5:退出");
input = sc.next();
if ("1".equals(input)) {
long id = acc2.getId();
System.out.println("请输入取款金额:");
String in = sc.next();
double money = Double.parseDouble(in);
bank.withdraw(id, money);
System.out.println(acc2.getName() + "的余额为:"
+ acc2.getBalance() + " 元");
} else if ("2".equals(input)) {
long id = acc2.getId();
System.out.println("请输入存款金额:");
String in = sc.next();
double money = Double.parseDouble(in);
bank.deposit(id, money);
System.out.println(acc2.getName() + "的余额为:"
+ acc2.getBalance() + " 元");
} else if ("3".equals(input)) {
System.out.println("您的卡号 : " + acc2 + " 余额为:"
+ acc2.getBalance() + " 元");
} else if ("4".equals(input)) {
System.out.println("请输入当前密码 最多三次 :");
for (int i = 0; i < 3; i++) {
input = sc.next();
if (!input.equals(acc2.getPassword())) {
System.out.println("错误,请重新输入当前密码:");
} else if (input.equals(acc2.getPassword())) {
String password = "";
String[] acc = new String[2];
String[] arr = { "输入新密码", "重新输入新密码" };
for (int j = 0; j < arr.length; j++) {
System.out.println("请" + arr[j]);
password = sc.next();
acc[j] = password;
if (j == 0) {
continue;
}
if (acc[0].equals(acc[1])) {
break;
} else {
System.out.println("两次密码不同,请重新输入!!");
j = j - 2;
}
}
acc2.setPassword(password);
System.out.println("恭喜你,修改成功,您的新密码为:"
+ password);
break;
}
continue;
}
} else if ("5".equals(input)) {
System.out.println("欢迎下次登录!再见!");
break;
}
}
} else if ("3".equals(input)) {
System.out.println("欢迎下次使用!再见!");
break;
}
}
}
/**
* 得到用户输入
*
* @param type
* @return account
*/
public static Account getAccount(int type) {
Scanner sc = new Scanner(System.in);
String[] acc = new String[2];
String[] arr = { "输入密码", "重新输入密码" };
if (type == 0) {
System.out.println("您选择了借记卡,请输入您的姓名:");
} else {
System.out.println("您选择了信用卡,请输入您的姓名:");
}
String name = sc.next();
String password = "";
Account account = null;
for (int i = 0; i < arr.length; i++) {
System.out.println("请" + arr[i]);
password = sc.next();
acc[i] = password;
if (i == 0) {
continue;
}
if (acc[0].equals(acc[1])) {
break;
} else {
System.out.println("两次密码不同,请重新输入!!");
i = i - 2;
}
}
System.out.println("请输入邮箱email:");
String email = sc.next();
System.out.println("请输入身份证号:");
String personId = sc.next();
if (type == 0) {
account = new DebitAccount(password, name, personId, email, 0.0);
} else {
System.out.println("请输入身此卡号的透支额度:");
String ceilingStr = sc.next();
double ceiling = Double.parseDouble(ceilingStr);
account = new CreditAccount(password, name, personId, email, 0.0,
ceiling);
}
return account;
}
}