rushdie

Bank

Dec 21st, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.37 KB | None | 0 0
  1. package BankAccounts;
  2.  
  3.  
  4. public class Account implements AccountTotalable {
  5.     public class AccountTotalable {
  6.  
  7.     }
  8.     protected int AccountNum;
  9.     protected  String AccountType;
  10.     protected  double Amount;
  11.     protected double Balance;
  12.     protected double FeeCharge;
  13.     protected static int AccountID;
  14.     protected  int CounterByType = 0;
  15.     protected  int CounterByNumber = 0;
  16.  
  17. /**
  18.      * @param accountNum
  19.      * @param accountType
  20.      * @param balance
  21.  * @param CounterByNumber
  22.  * @param CounterByType
  23.      */
  24.     public Account(int accountNum, String accountType, double balance, int accountID) {
  25.         super();
  26.         this.AccountNum = accountNum;
  27.         this.AccountType = accountType;
  28.         this.Balance = balance;
  29.         this.AccountID = AccountID;
  30.         AccountID =++CounterByType;
  31.         AccountID =++CounterByNumber;
  32.        
  33.     }
  34.  
  35. public double getBalance()
  36. {
  37.     return this.Balance;
  38. }
  39.  
  40. public int getAccountNum()
  41. {
  42.     return this.AccountNum ;
  43. }
  44.  
  45. public int getTotalAccountByNum(int CounterByNumber)
  46. {
  47.     return this.CounterByNumber;
  48. }
  49.  
  50. public int setTotalAccountByNum(){
  51.     return this.CounterByNumber ;
  52. }
  53.  
  54. public int getTotalAccountByType(int CounterByType)
  55. {
  56.     return this.CounterByType;
  57. }
  58.  
  59. public int setTotalAccountByType(int CounterByType, int TotalAccountByType){
  60.     return this.CounterByType ;
  61. }
  62.  
  63. public void getAccountByType(Enum AccountByType,int AccountNum )
  64. {
  65.     this.AccountNum = AccountNum ;
  66. }
  67.  
  68. public boolean withDraw(double Amount)
  69. {
  70.     if(Balance > 0 && Balance != 0){
  71.         this.Balance = Balance - Amount;
  72.         return true;
  73.     }
  74.     return false;
  75.    
  76. }
  77.  
  78. public double Balance(double Amount)
  79. {
  80.     if(Balance > 0 && Balance != 0){
  81.     Balance = Balance - Amount;}
  82.     return this.Balance;
  83. }
  84.  
  85. public void Deposit(double Amount){
  86.     Balance = Balance + Amount;
  87. }
  88.  
  89. public double getDeposit() {
  90.     return this.Amount;
  91. }
  92.  
  93. public double setDeposit(){
  94.     return Amount;
  95.    
  96. }
  97.  
  98. public int AccountByType(int CounterByType)
  99. {
  100.     return this.CounterByType += 1;
  101.     }
  102.  
  103.     public int getAccountFee(int FeeCharge)
  104.     {
  105.         return FeeCharge;
  106.     }
  107.    
  108.     public double setAccountFee(int AccountNum)
  109.     {
  110.         switch(AccountNum){
  111.         case 10001:
  112.             return this.FeeCharge = Balance * 0.05;
  113.         case 20001:
  114.             return this.FeeCharge = Balance * 0.0;
  115.         case 30001:
  116.             return this.FeeCharge = Balance * 0.02;
  117.         case 40001:
  118.             return this.FeeCharge = Balance * 0.01;
  119.         }
  120.         return this.FeeCharge;
  121.     }
  122.    
  123.     public BankAccounts.AccountsByName.AccountByType getAccountByType(int AccountNum) {
  124.         switch(this.AccountNum){
  125.         case 10001:
  126.         return BankAccounts.AccountsByName.AccountByType.REGULAR;
  127.         case 20001:  
  128.         return BankAccounts.AccountsByName.AccountByType.TEENAGE;
  129.         case 30001:  
  130.         return BankAccounts.AccountsByName.AccountByType.BUSSINESS;
  131.         case 40001:  
  132.         return BankAccounts.AccountsByName.AccountByType.STUDENT;
  133.         }
  134.         return BankAccounts.AccountsByName.AccountByType.OTHER;
  135.     }
  136.  
  137.     public double getBalance(double Balance) {
  138.         return this.Balance = Balance  - (Balance * FeeCharge);
  139.     }
  140.    
  141.    
  142.     public String toString()
  143.     {
  144.         return " Name: "+AccountType+
  145.                 " Number: "+AccountNum+
  146.                 " Balance: " +Balance+" Fees Charged: "+FeeCharge+
  147.                 " Deposit: " +Amount+
  148.                 " Counter By Number: "+CounterByNumber+
  149.                 " Counter By Type: "+CounterByType;
  150.    
  151.     }
  152.  
  153. }
  154. package BankAccounts;
  155.  
  156. public class Students extends Account implements AccountTotalable {
  157.     protected int NumberPayments = 0;
  158.     protected double SumofPayment = 0;
  159.     protected double LoanAmount = 0;
  160.     protected boolean HaveLoan = true;
  161.  
  162.    
  163.     /**
  164.      * @param accountNum
  165.      * @param accountType
  166.      * @param balance
  167.      * @param numberPayments
  168.      * @param loanAmount
  169.      * @param SumofPayment
  170.      * @param CounterByNumber
  171.      * @param CounterByType
  172.      */
  173.     public Students(int accountNum, String accountType, double balance, int numberPayments, double loanAmount, int AccountID) {
  174.         super(accountNum, accountType, balance, numberPayments);
  175.         this.NumberPayments = numberPayments;
  176.         this.LoanAmount = loanAmount;
  177.         this.AccountID = AccountID;
  178.         AccountID =++CounterByType;
  179.         AccountID =++CounterByNumber;
  180.  
  181.        
  182.             }
  183.  
  184.     public int getNumberPayments() {
  185.         return NumberPayments;
  186.     }
  187.  
  188.     public void setNumberPayments(int numberPayments) {
  189.         NumberPayments = numberPayments;
  190.     }
  191.  
  192.     public double getLoanAmount() {
  193.         return LoanAmount;
  194.     }
  195.  
  196.     public void setLoanAmount(double LoanAmount) {
  197.             this.LoanAmount = LoanAmount;
  198.         }
  199.    
  200.     public double getSumofPayment() {
  201.         this.SumofPayment = LoanAmount / NumberPayments;
  202.  
  203.         return SumofPayment;
  204.     }
  205.  
  206.     public void setSumofPayment(double SumofPayment) {
  207.         this.SumofPayment = SumofPayment;
  208.     }
  209.  
  210.     public int getAccountNum() {
  211.         return AccountNum;
  212.     }
  213.  
  214.     public void setAccountNumber(int AccountNum) {
  215.         this.AccountNum = AccountNum;
  216.     }
  217.  
  218.     public double getBalance(double Balance) {
  219.         this.Balance = (LoanAmount + (LoanAmount * FeeCharge)) / NumberPayments;
  220.  
  221.         return this.Balance;
  222.     }
  223.     public void Deposit(double Amount){
  224.         Balance = Balance + Amount;
  225.     }
  226.  
  227.     public double getDeposit() {
  228.         return this.Amount;
  229.     }
  230.  
  231.     public double setDeposit(){
  232.         return Amount;
  233.        
  234.     }
  235.  
  236.  
  237.     public String toString()
  238.     {
  239.         return " Name: "+AccountType+
  240.                 " Number: "+AccountNum+
  241.                 " Balance: " +Balance+" Fees Charged: "+FeeCharge+
  242.                 " Deposit: " +Amount+
  243.                 " Counter By Number: "+CounterByNumber+
  244.                 " Counter By Type: "+CounterByType;
  245.  
  246.    
  247.     }
  248.  
  249. }
  250. package BankAccounts;
  251.  
  252. public interface AccountTotalable {
  253.  
  254.     public default double getBalance(double Balance) {
  255.         return Balance;
  256.     }
  257. }
  258. package BankAccounts;
  259.  
  260. public class AccountsByName extends Account implements AccountTotalable{
  261.    
  262.     public AccountsByName(String AccountByType, int AccountNum, double Balance, Enum AccountBytype) {
  263.         super(AccountNum, AccountByType, Balance, AccountID);
  264.     }
  265.  
  266. public enum AccountByType {
  267.     REGULAR("Regular", 10001),
  268.     TEENAGE("Teenage", 20001),
  269.     BUSSINESS("Bussiness", 30001),
  270.     STUDENT("Student", 40001),
  271.     OTHER("Other", 50001);
  272.  
  273.     protected final String Description;
  274.     protected final int AccountNumber;
  275.  
  276.     AccountByType(String Description, int AccountNumber)
  277.     {
  278.         this.Description = Description;
  279.         this.AccountNumber = AccountNumber;
  280.     }
  281.  
  282. }
  283.  
  284.  
  285. private int AccountNumber;
  286. public String getDescription()
  287.     {
  288.         return getDescription();
  289.     }
  290.  
  291.     public int getaccountNumber()
  292.     {
  293.         return getaccountNumber();
  294.     }
  295.    
  296.  
  297.     public String getAccountsByType(int AccountNumber){
  298.     this.setAccountNumber(AccountNumber);
  299.         switch(AccountNumber){
  300.             case 10001:
  301.                 this.setDescription("Regular");
  302.                 CounterByNumber += 1;
  303.                 CounterByType += 1;
  304.                 break;
  305.             case 20001:
  306.                 this.setDescription("Teenage");
  307.                 CounterByNumber += 1;
  308.                 CounterByType += 1;
  309.                 break;
  310.             case 30001:
  311.                 this.setDescription("Bussiness");
  312.                 CounterByNumber += 1;
  313.                 CounterByType += 1;
  314.                 break;
  315.             case 40001:
  316.                 this.setDescription("Student");
  317.                 CounterByNumber += 1;
  318.                 CounterByType += 1;
  319.  
  320.                 break;
  321.             }
  322.         return "Account Number is Not Defined!";
  323.         }
  324.  
  325.     private String setDescription(String string) {
  326.         // TODO Auto-generated method stub
  327.         return getDescription();
  328.     }
  329.  
  330.     protected int NumberOfPayments;
  331.     protected  double LoanSum;
  332.    
  333.     public int getAccountNumber() {
  334.         return AccountNumber;
  335.     }
  336.  
  337.     public void setAccountNumber(int AccountNumber) {
  338.         this.AccountNumber = AccountNumber;
  339.     }
  340.  
  341.     public int getNumberOfPayments() {
  342.         return NumberOfPayments;
  343.     }
  344.  
  345.     public void setNumberOfPayments(int NumberOfPayments) {
  346.         this.NumberOfPayments = NumberOfPayments;
  347.     }
  348.  
  349.     public double getLoanSum() {
  350.         return LoanSum;
  351.     }
  352.  
  353.     public void setLoanSum(double loanSum) {
  354.         LoanSum = loanSum;
  355.     }
  356.  
  357.     public String toString()
  358.     {
  359.         return  "Account Holder Name: "+ AccountType+
  360.                 " Number of Payments: "+NumberOfPayments+
  361.                 " Loan Sum: "+LoanSum;
  362.     }
  363.    
  364.  
  365. }
  366. package BankAccounts;
  367.  
  368. public class BankAccountTester {
  369.  
  370.     public static void main(String[] args) {
  371.         Account[] Cust1 = new Account[4];
  372.         Cust1[0] = new Account(10001, "Foofo ", 11500, 1);
  373.         Cust1[1] = new Students(40001, "Moomo ", 15000, 20, 20000, 2);
  374.         Cust1[2] = new Account(20001, "Mousee ", 7000, 3);
  375.         Cust1[3] = new Students(40001, "Seecee ", 12000, 10, 20000, 4);
  376.  
  377.         for (int i = 0; i < Cust1.length; i++) {
  378.             if (Cust1[i] instanceof Account) {
  379.                 System.out.println(Cust1[i]);
  380.                 Cust1[i].withDraw(1000);
  381.                 Cust1[i].Deposit(5000);
  382.                 System.out.println(Cust1[i]);
  383.                
  384.                 System.out.println("================================");
  385.  
  386.                 int Actnum2 = Cust1[i].getAccountNum();
  387.                 System.out.println(Cust1[i].getAccountFee(Actnum2));
  388.                 System.out.println(Cust1[i].getAccountByType(Actnum2));
  389.                 System.out.println("Balance: " + (Cust1[i].getBalance()));
  390.                
  391.             } else if (Cust1[i] instanceof Students) {
  392.                 System.out.println(Cust1[i]);
  393.                
  394.                 int Actnum = Cust1[i].getAccountNum();
  395.                 System.out.println(Cust1[i].getAccountFee(Actnum));
  396.                 System.out.println(Cust1[i].getAccountByType(Actnum));
  397.                
  398.                 Cust1[i].getAccountFee(400);
  399.                 Cust1[i].withDraw(4000);
  400.                 System.out.println(Cust1[i]);
  401.                 Cust1[i].Deposit(250000);
  402.                 System.out.println(Cust1[i]);
  403.  
  404.                 System.out.println("Balance: " + (Cust1[i].getBalance()));
  405.             }
  406.         }
  407.     }
  408.  
  409. }
Add Comment
Please, Sign In to add comment