Guest User

myBank

a guest
Aug 16th, 2017
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. teenage.class
  2. =================
  3. package ClsBank;
  4.  
  5. public class Teenage extends Account {
  6.  
  7.     public Teenage(String accountName, String id, int age) {
  8.         super(accountName, id, age);
  9.         Account.teenageAccountCounter+=1;
  10.         this.accountNumber=Integer.parseInt(Account.TEENAGE_PERFIX+Account.teenageAccountCounter);
  11.     }
  12.  
  13. }
  14.  
  15.  
  16. account.class
  17. ====================
  18. package ClsBank;
  19.  
  20. public abstract class Account implements AccountAble {
  21.  
  22.     // Static Variable
  23.     protected static int studentAccountCounter = 0;
  24.     protected static int bussniessAccountCounter = 0;
  25.     protected static int regularAccountCounter = 0;
  26.     protected static int teenageAccountCounter = 0;
  27.     final protected static String TEENAGE_PERFIX="4";
  28.    
  29.     // normal variable
  30.     protected int accountNumber = 0;
  31.     protected int age = 0;
  32.     protected String accountType = ""; // st,bu,re,te
  33.     protected String accountName = "";
  34.     protected String id;
  35.     protected double balance=0;
  36.     protected int fee=-1;
  37.     protected boolean isClosed=false;
  38.     public Account(String accountName, String id, int age) {
  39.         this.accountName = accountName;
  40.         this.id = id;
  41.         this.age = age;
  42.         this.balance=0;
  43.     }
  44.  
  45.     @Override
  46.     public int getTotalAccounts() {
  47.  
  48.         return (this.studentAccountCounter + this.bussniessAccountCounter
  49.                 + this.regularAccountCounter + this.teenageAccountCounter);
  50.     }
  51.  
  52.     @Override
  53.     public int getTotalAccountByType() {
  54.         // st,bu,re,te
  55.         int returnValue = 0;
  56.  
  57.         String myAccount = this.accountNumber+"";
  58.        
  59.         switch (myAccount.charAt(0))
  60.         {
  61.             case '1':
  62.                 returnValue=this.studentAccountCounter;
  63.                 break;
  64.             case '2':
  65.                 returnValue=this.bussniessAccountCounter;
  66.                 break;
  67.             case '3':
  68.                 returnValue=this.regularAccountCounter;
  69.                 break;
  70.             case '4':
  71.                 returnValue=this.teenageAccountCounter;
  72.                 break;
  73.             default:
  74.                 returnValue=0;
  75.  
  76.         }
  77.  
  78.         return returnValue;
  79.     }
  80.  
  81.     @Override
  82.     public double getBalance() {
  83.        
  84.         return this.balance;
  85.     }
  86.  
  87.    
  88.  
  89.     @Override
  90.     public void setAccountFee(int fee) {
  91.         this.fee=fee;
  92.  
  93.     }
  94.  
  95.     @Override
  96.     public double getAccountFee() {
  97.         // TODO Auto-generated method stub
  98.         return this.fee;
  99.     }
  100.  
  101.     @Override
  102.     public void withDraw(double amount) throws Exception {
  103.         checkConditions(amount);
  104.         double amountFee=amount*(1+this.fee/100);
  105.         if (amountFee>this.balance) throw new Exception("Insffiecent funds");
  106.         this.balance-=amountFee;
  107.     }
  108.    
  109.     @Override
  110.     public void deposit(double amount) throws Exception {
  111.         checkConditions(amount);
  112.         double amountFee=amount*(1-this.fee/100);
  113.         this.balance+=amountFee;
  114.     }
  115.    
  116.     private void checkConditions(double amount) throws Exception
  117.     {
  118.         if (this.fee<0) throw new Exception("Please set fee to the account");
  119.         if (amount<0) throw new Exception("Number must be positive"); //Eti Alon
  120.         if (amount>10000) throw new Exception("Limited to 9,999Nis only");
  121.         if (this.isClosed) throw new Exception("Account is closed");
  122.     }
  123.  
  124.     @Override
  125.     public int getAccountNumber() {
  126.         return this.accountNumber;
  127.     }
  128.  
  129.     @Override
  130.     public int getAge() {
  131.         return this.age;
  132.     }
  133.  
  134.     @Override
  135.     public void closeAccount() throws Exception {
  136.         if (this.balance<0) throw new Exception("the account in overdraft");
  137.         if (this.balance>0) throw new Exception("Withdraw all the money");
  138.        
  139.         //close the account
  140.         this.isClosed=true;
  141.     }
  142.  
  143. }
  144.  
  145.  
  146. accountable.interface
  147. ==========================
  148. package ClsBank;
  149.  
  150. public interface AccountAble {
  151.     int getTotalAccounts(); //get total of accounts in bank
  152.     int getTotalAccountByType ();
  153.     double getBalance();
  154.     void withDraw(double amount) throws Exception;
  155.     void setAccountFee(int fee);
  156.     double getAccountFee();
  157.     void deposit(double amount) throws Exception;
  158.     int getAccountNumber();
  159.     int getAge();
  160.     void closeAccount() throws Exception;
  161. }
Add Comment
Please, Sign In to add comment