?? bank.java
字號:
package biz;
import dao.AccountDao;
import dao.impl.AccountFileDao;
import Exception.BalanceNotEnoughException;
import Exception.LoginException;
import Exception.RegisterException;
import entity.*;
public class Bank implements IBank{
AccountDao dao=new AccountFileDao();
/* private Account[] accounts=new Account[10];
private int index=0;
private void expand(){
Account[] as=new Account[accounts.length*2];
System.arraycopy(accounts,0,as,0,accounts.length);
accounts=as;
} */
public long regist(String name,String password,String againPassword,String personId,int type)throws RegisterException{
if(password.equals(againPassword)){
Account a=null;
if(type==0){
a=new SavingAccount(name,password,personId);
}
if(type==1){
a=new CreditAccount(name,password,personId);
}
dao.saveAccount(a) ;
return a.getId();
}else{
throw new RegisterException("兩次密碼不一致");
//System.out.println("對不起,密碼錯誤!");
//return -1;
}
}
public long login(long id,String password) throws LoginException{
// 根據id查找帳戶,獲取該帳戶的password
Account a=queryById(id);
if(a==null){
throw new LoginException("帳戶不存在");
// System.out.println("對不起,帳戶不存在");
// return -1;
}
String password1=a.getPassword();
// 判斷兩個password是否相等
if(password1.equals(password)){
return id;
}else
throw new LoginException("密碼錯誤");
//System.out.println("對不起,密碼錯誤");
//return -1;
}
public Account deposit(long id,double money){
Account a=dao.findAccountById(id);
a.deposit(money);
dao.saveAccount(a);
return a;
}
public Account withdraw(long id,double money) throws BalanceNotEnoughException{
Account a=dao.findAccountById(id);
a.withdraw(money);
dao.saveAccount(a);
return a;
}
public double queryBalance(long id){
// 根據id查找帳戶
Account a=queryById(id);
if(a==null){
System.out.println("對不起,帳戶不存在");
return -1;
}else{
return a.getBalance();
}
}
private Account queryById(long id){
return dao.findAccountById(id) ;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -