Advertisement
vesso8

Bank

May 13th, 2021
42
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Bank_Acount;
  2.  
  3. import java.util.Set;
  4. import java.util.HashMap;
  5.  
  6. public class Bank {
  7. private HashMap<Integer,Integer> accounts = new HashMap<>();
  8. private double rate = 0.01;
  9. private int nextacct = 0;
  10. public int newAccount(){
  11. int acctnum = nextacct ++;
  12. accounts.put(acctnum, 0);
  13. return acctnum;
  14. }
  15. public int getBalance(int acctnum) {
  16. return accounts.get(acctnum);
  17. }
  18. public void deposit(int acctnum, int amt){
  19. int balance = accounts.get(acctnum);
  20. accounts.put(acctnum, balance + amt);
  21. }
  22. public boolean authorizeLoan(int acctnum, int loanamt){
  23. int balance = accounts.get(acctnum);
  24. return balance >= loanamt / 2;
  25. }
  26. public String toString(){
  27. Set<Integer> accts = accounts.keySet();
  28. String result = "The bank has " + accts.size() + "accounts.";
  29. for (int i: accts)
  30. result += "\n\tBank_Acount.Bank account " + i + ": balance=" + accounts.get(i);
  31. return result;
  32. }
  33. public void addInterest(){
  34. Set<Integer> accts = accounts.keySet();
  35. for(int i :accts){
  36. int balance = accounts.get(i);
  37. int newbalance = (int) (balance * (1 + rate));
  38. accounts.put(i, newbalance);
  39. }
  40. }
  41. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement