| 2 | |
| 3 | import java.util.HashMap; |
| 4 | public class bankService { |
| 5 | private HashMap<Integer,BankAccout> accounts=new HashMap<>(); |
| 6 | void AccountCreation(int accno,String name,String type,int pin) throws Accountalreadyexception{ |
| 7 | if(accounts.containsKey(accno)){ |
| 8 | throw new Accountalreadyexception("Account Already exist in this Number"); |
| 9 | }else{ |
| 10 | BankAccout acc=new BankAccout(accno, name, type, pin); |
| 11 | accounts.put(accno, acc); |
| 12 | } |
| 13 | } |
| 14 | BankAccout Login(int accno,int pin) throws AccountNotFoundException,InvalidPinException{ |
| 15 | if(!accounts.containsKey(accno)){ |
| 16 | throw new AccountNotFoundException("Account not Found"); |
| 17 | } |
| 18 | BankAccout acc=accounts.get(accno); |
| 19 | if(!acc.pinValidation(pin)){ |
| 20 | throw new InvalidPinException("Invalid pin"); |
| 21 | } |
| 22 | return acc; |
| 23 | } |
| 24 | void transfrer(int accno1,int accno2,double amount)throws AccountNotFoundException,Insufficientexception{ |
| 25 | if(!accounts.containsKey(accno1)){ |
| 26 | throw new AccountNotFoundException("Sender Account not Found"); |
| 27 | } |
| 28 | if(!accounts.containsKey(accno2)){ |
| 29 | throw new AccountNotFoundException("Receiver Account not Found"); |
| 30 | } |
| 31 | if(amount<=0){ |
| 32 | throw new IllegalArgumentException(); |
| 33 | } |
| 34 | BankAccout sender=accounts.get(accno1); |
| 35 | BankAccout receiver=accounts.get(accno2); |
| 36 | if((sender.getBalance()>=amount)){ |
| 37 | sender.withdraw(amount); |
| 38 | } |
| 39 | else{ |
| 40 | throw new Insufficientexception("Insufficient funds"); |
| 41 | } |
| 42 | receiver.deposit(amount); |
| 43 | sender.addtransaction("Transfer", amount,"Transferred "+amount+ "to Acc"+accno2); |
| 44 | receiver.addtransaction("Transfer", amount,"Received"+amount+ "From Acc"+accno1); |
| 45 | } |
| 46 | } |
nothing calls this directly
no outgoing calls
no test coverage detected