Guest User

Account

a guest
Aug 9th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 19.76 KB | None | 0 0
  1. package Tester;
  2.  
  3. import bank.Account1;
  4. import bank.Bussniess;
  5. import bank.Student;
  6. import bank.Teenage;
  7. import bank.ageExcepptions;
  8. import bank.exceptionsAccount;
  9. import bank.Account;
  10. import java.util.Date;
  11. import java.util.InputMismatchException;
  12. import java.util.Scanner;
  13. import bank.regular;
  14. import bank.loanable;
  15.  
  16. public class TestNewAccount {
  17.  
  18.     public static void main(String[] args) {
  19.  
  20.         Scanner in=new Scanner(System.in);
  21.    
  22.             try {  
  23.             Account1[] Account= new Account1[7];
  24.             Account[0]=new Student("ahmad", 1236554, 29);
  25.             Account[1]=new Student("zahra", 1569582,30);
  26.             Account[2]=new Bussniess("foad", 1245423,19);
  27.             Account[3]=new regular("rami", 2540063, 18);          
  28.             Account[4]=new Student("rana", 3644263,30);
  29.             Account[5]=new Student("RON", 3114263,25);
  30.             Account[6]=new Bussniess("JUN", 9814263,90);
  31.            
  32.             //show total accounts , show total bussniess count & student
  33.             //---------------------------------------------------------------------------
  34.             System.out.printf("Total Accounts is %s \n",((Account)Account[0]).getCount());  
  35.             System.out.println(((Bussniess) Account[2]).getBussniessCount()+("  of them  is Bussniess Accounts "));
  36.             System.out.println(((Student) Account[1]).getStudentCount()+("  of them  is Student Accounts "));
  37.             //----------------------------------------------------------------------------
  38.            
  39.            
  40.             //-----------------------------------------------------------------------------
  41.             ((Account)Account[6]).setFee(0.005);     // personal fee
  42.             ((Account)Account[6]).setBalance(2000); // set balance
  43.             ((Account)Account[6]).setLimit(3000);  //  personal framework
  44.             System.out.println(Account[6].withDraw(3000)); // with draw
  45.             System.out.println(Account[6].toString());  //print all details of account 6
  46.             //------------------------------------------------------------------------------
  47.            
  48.             //------------------------------------------------------------------------------
  49.             System.out.println((((Student)Account[1]).toString()));// Student get a loan that equal to 20000
  50.             System.out.println( ((Student)Account[1]).getLoan(20000, 12));//
  51.             System.out.println( ((Student)Account[1]).isThereIsLoan());
  52.             System.out.println(((Student)Account[1]).deposit(20000));
  53.             ((Student)Account[1]).closeLoan();                      //try to close loan
  54.             ((Student)Account[1]).closeAccount();                   //try to close account
  55.             //-------------------------------------------------------------------------------
  56.            
  57.            
  58.             //-------------------------------------------------------------------------------
  59.             System.out.println(((Student)Account[1]).loanReturnByMonth()); // check value of loan return by month
  60.             System.out.println("Enter loan value you want and payment");
  61.             System.out.println(((Student)Account[0]).getLoan(in.nextDouble(), in.nextInt()));// try to get a new loan
  62.             //--------------------------------------------------------------------------------
  63.         }
  64.    
  65.    
  66.         catch(InputMismatchException e){
  67.             System.out.println(e.getMessage());
  68.         }
  69.          
  70.  
  71.         catch(ArithmeticException e){
  72.             System.out.println(e.getMessage());
  73.         }
  74.         catch(Exception e){
  75.             System.out.println(e.getMessage());
  76.        }
  77.    
  78.     }
  79. }
  80.  
  81. ================================================================================
  82.  
  83. package bank;
  84. public class Account implements Account1 {
  85.     //-----------------------------------------------------------------------------
  86.  
  87.     protected int PersonalLimit=0;  //account framework    
  88.     protected String typeOfaccount;    
  89.     protected String name;
  90.     protected  int id;
  91.     protected double balanc=0;
  92.     protected static int count=0;
  93.     protected static int studentCount=0;
  94.     protected static int bussniessCount=0;
  95.     protected static int regularCount=0;
  96.     protected static int teenageCount=0;
  97.     protected static int soldierCount=0;
  98.     protected static double fee=0.00;
  99.     protected int accountNumber=0;
  100.     protected int age=0;     
  101.     protected int limit=0;  // Account Framework  
  102.     protected int loan=0;  //General Loan  
  103.     //-----------------------------------------------------------------------------
  104.  
  105.     public Account(String name, int id, int age) throws exceptionsAccount {
  106.         super();
  107.         this.name = name;
  108.         this.id = id;
  109.         this.count = count+1;
  110.         this. accountNumber= this.id;
  111.         this.age=age;
  112.         if (this.id<100000000 && this.id>999999){
  113.             this.id=id;
  114.         }
  115.         else  idException.idException();
  116.           }
  117.    
  118.     public int getPersonalLimit() {
  119.         return PersonalLimit;
  120.     }
  121.  
  122.     public void setPersonalLimit(int personalLimit) {
  123.         this.limit = personalLimit;
  124.     }
  125.  
  126.     public String getTypeOfaccount() {
  127.         return typeOfaccount;
  128.     }
  129.  
  130.     public void setTypeOfaccount(String typeOfaccount) {
  131.        
  132.         this.typeOfaccount = typeOfaccount;
  133.     }
  134.  
  135.     public static int getBussniessCount() {
  136.         return bussniessCount;
  137.     }
  138.  
  139.     public static int getStudentCount() {
  140.         return studentCount;
  141.     }
  142.     public static int getRegularCount() {
  143.         return regularCount;
  144.     }
  145.     public static int getTeenageCount() {
  146.         return teenageCount;
  147.     }
  148.     @Override
  149.     public int getTotalAccount() {
  150.         // TODO Auto-generated method stub
  151.         return 0;
  152.     }
  153.     public void setBalance(double balanc){
  154.    
  155.         if (balanc>0){
  156.         this.balanc=balanc;
  157.         }
  158.         else {
  159.             try{
  160.                 balancException.balancException();
  161.             }
  162.             catch(Exception e){
  163.                 System.out.println(e.getMessage());
  164.             }
  165.         }
  166.     }
  167.    
  168.  
  169.     @Override
  170.     public double getBalanc() {
  171.        
  172.         return this.balanc;
  173.     }
  174.     @Override
  175.     public boolean withDraw(double amount) throws exceptionsAccount {
  176.     double amountFee=amount*(1+this.fee);
  177.     if (this.balanc>amountFee)
  178.     {
  179.         this.balanc-=amountFee;
  180.         return true;
  181.     }
  182.     else if(this.balanc<amountFee && amountFee <(this.balanc+this.limit))
  183.     {
  184.     this.balanc-=amountFee;
  185.     return true;   
  186.     }
  187.         else {
  188.               try {
  189.                 withDrawException.withDrawException();                }
  190.               catch (Exception e) {
  191.                 System.out.println("you can't with draw this amount:" +" '"
  192.               + amountFee +"' "+ e.getMessage()+(this.balanc+this.limit)+" NIS");  
  193.                 }
  194.               return false;
  195.          }
  196.     }
  197.  
  198.     public double getAccountFee() {
  199.         return this.fee;
  200.     }
  201.    
  202.     @Override
  203.     public String deposit(double amount) {
  204.         String msg = null;
  205.         if(amount>0){
  206.             msg="your balnc now is : " + this.balanc+amount;
  207.             return msg ;
  208.         }
  209.         else
  210.            try {
  211.                depositException.depositException();}
  212.         catch (exceptionsAccount e)
  213.                 {
  214.                msg= "your balnc now is : " +" '" +  this.balanc +"' "+ " "+ e.getMessage();
  215.                 }
  216.                 return msg;
  217.              }
  218.    
  219.  
  220.     public static double getFee() {
  221.         return fee;
  222.     }
  223.  
  224.     public static void setFee(double fee) {
  225.         Account.fee = fee;
  226.     }
  227.  
  228.     @Override
  229.     public int getAccountNumber() {
  230.        
  231.         return this.accountNumber;
  232.     }
  233.    
  234.     @Override
  235.     public int getAge() {
  236.        
  237.         return this.age;
  238.     }  
  239.  
  240.  
  241.     public  int getCount() {
  242.         return count;
  243.     }
  244.     @Override
  245.  
  246.     public int getTotalAccountByType(String Type) {
  247.         // TODO Auto-generated method stub
  248.         if(this instanceof Student){
  249.            
  250.            
  251.         }
  252.         if ( Type =="Teenage")
  253.                 {
  254.             return teenageCount;
  255.                 }
  256.         if (Type=="Bussniess")
  257.         {
  258.             return  bussniessCount;
  259.         }
  260.         if (Type=="Student")
  261.         {
  262.             return  studentCount;
  263.         }
  264.         if (Type=="Student")
  265.         {
  266.             return  studentCount;
  267.         }
  268.         //if (Type=="regular")
  269.         {
  270.             return  regularCount;
  271.         }
  272.        
  273.     }
  274.    
  275.     public int getLimit() {
  276.         return limit;
  277.     }
  278.  
  279.     public void setLimit(int limit) {
  280.         this.limit = limit;
  281.     }
  282.    
  283.     @Override
  284.     public String toString() {
  285.         return "Account [name=" + name + ", id=" + id +
  286.                 " accountNumber=" + accountNumber +
  287.                 " typeOfaccount=" + getTypeOfaccount()
  288.                 + " balanc= "+ balanc + " accountNumber=" + accountNumber+"]";
  289.     }
  290.  
  291.     @Override
  292.     public void setAccountFee(int fee) {
  293.        
  294.         this.fee=fee;
  295.     }
  296.     @Override
  297.     public void closeAccount() throws exceptionsAccount {
  298.        
  299.         if(this.balanc==0 && this.loan==0){
  300.         System.out.println("your account is closed");
  301.         }
  302.         else
  303.             closeAccountException.closeAccountException();
  304.        
  305.     }
  306. }
  307. ====================================================================================================
  308. package bank;
  309.  
  310. public interface Account1 {
  311.     int getTotalAccount();
  312.     int getTotalAccountByType(String Type);
  313.     double getBalanc();
  314.     boolean withDraw(double amount) throws Exception;
  315.     void setAccountFee(int fee);    
  316.     double getAccountFee();
  317.     String deposit(double amount);
  318.     int getAccountNumber() throws Exception;
  319.     int getAge();
  320.     int getCount();
  321.     void closeAccount() throws exceptionsAccount;
  322.    
  323. }
  324.  
  325. ==============================================================================================
  326. package bank;
  327.  
  328. public class ageExcepptions extends exceptionsAccount {
  329.     public ageExcepptions(){
  330.     super("to open account age must be more than 15 year old" );
  331. }
  332.     public static void ageExcepptionsRegular()throws exceptionsAccount{
  333.    
  334.     throw new exceptionsAccount  ("To Create Regular account or Bussniess account or Student account, age"
  335.                                       + "   must be more than 18 Try"
  336.                                       + " to Create another type"
  337.                                       + " account");
  338.        
  339.     }
  340.     public static void ageExcepptionsTeenage()throws exceptionsAccount{
  341.        
  342.         throw new exceptionsAccount  ("To Create Teenage account age"
  343.                                       + "must be between 16-18 Try"
  344.                                       + " to Create another type"
  345.                                       + "of account");
  346.  
  347.     }
  348.     public static void ageExcepptionsStudent()throws exceptionsAccount{
  349.        
  350.         throw new exceptionsAccount  ("To Create Student account, age"
  351.                                       + "   must be more than 18, Try"
  352.                                       + " to Create another type"
  353.                                       + " account");
  354.  
  355.     }
  356.    
  357.     public static void ageExcepptionsAccount()throws exceptionsAccount{
  358.        
  359.         throw new exceptionsAccount  ("To Create Account, age"
  360.                                       + "   must be more than 16 ");
  361.                        
  362.     }
  363.     public static void ageExcepptionsBussniess()throws exceptionsAccount{
  364.        
  365.         throw new exceptionsAccount  ("To Create Bussniess account, age"
  366.                                           + "must be more than 18 Try"
  367.                                           + " to Create another type"
  368.                                           + " account");
  369.            
  370.         }
  371.     public static void ageExcepptionsSoldier()throws exceptionsAccount{
  372.        
  373.         throw new exceptionsAccount  ("To Create Soldier account, age"
  374.                                           + "must be more than 18 Try"
  375.                                           + " to Create another type"
  376.                                           + " account");
  377.            
  378.         }
  379. }
  380.  
  381. ==========================================================================================
  382. package bank;
  383.  
  384. public class attemptOpenNewLoan extends exceptionsAccount {
  385.     public attemptOpenNewLoan(){
  386.         super("failed becasue your have another loan" );
  387.     }
  388. }
  389. =============================================================================================
  390. package bank;
  391.  
  392. public class balancException extends exceptionsAccount {
  393.     public balancException(String msg){
  394.     super(msg);
  395.    
  396. }
  397.  
  398.     public static void balancException() throws Exception{
  399.         // TODO Auto-generated method stub
  400.     throw new Exception ("balanc must be more than 0 ");
  401.  
  402.     }
  403. }
  404. ===========================================================================================
  405. package bank;
  406.  
  407. public class Bussniess extends  loanFunctionOnAble{
  408.  
  409.     public Bussniess(String name, int id, int age) throws exceptionsAccount {
  410.         super(name, id, age);
  411.         // TODO Auto-generated constructor stub
  412.        
  413.         bussniessCount+=1;
  414.         this.loanPaymentLeft=0;
  415.         this.paymentValue=0.00;
  416.         this.loan=0;
  417.         this.payment=0;
  418.         this.limit=10000;
  419.         fee=0.002;
  420.         this.typeOfaccount="Bussniess";
  421.         this.accountNumber=Integer.parseInt("2" + id);
  422.         this.age=age;
  423.     if(this.age>18){
  424.         this.age=age;
  425.     }
  426.     else {
  427.       ageExcepptions.ageExcepptionsBussniess();
  428.    
  429.     }
  430.     }  
  431.        
  432.     }
  433.  
  434. =======================================================================================
  435. package bank;
  436.  
  437. public class closeAccountException extends exceptionsAccount {
  438.     public closeAccountException (String msg){
  439.     super(msg);
  440.     }
  441.    
  442.     public static void closeAccountException() throws exceptionsAccount{
  443.        
  444.     throw new exceptionsAccount  ("you must close the loan and the minus  ");
  445.    
  446.     }  
  447. }
  448.  
  449. ==================================================================================
  450. package bank;
  451.  
  452. public class depositException extends exceptionsAccount {
  453.     public depositException(String msg){
  454.         super(msg);
  455.     }
  456.    
  457.     public static void depositException() throws exceptionsAccount{
  458.        
  459.     throw new exceptionsAccount("Enter a possible values ");
  460.  
  461.     }
  462.  
  463. }
  464. ================================================================================
  465. package bank;
  466.  
  467. public class ErrorKeyBoardUsing extends exceptionsAccount {
  468.     public ErrorKeyBoardUsing(){
  469.         super(" recheck what you have written ");
  470.     }
  471. }
  472. =================================================================================
  473. package bank;
  474.  
  475. public class exceptionsAccount extends Exception{
  476.     public exceptionsAccount(String msg){
  477.         super(msg);
  478.     }
  479.     public exceptionsAccount(){
  480.         super("return to your Account details there is exception");
  481.     }
  482. }
  483. ================================================================================
  484. package bank;
  485.  
  486. public class getLoanException extends exceptionsAccount {
  487. public getLoanException(){
  488.     super("cliant can't take tow loan" );
  489.    
  490. }
  491. }
  492. ===============================================================================
  493. package bank;
  494. public class idException extends  exceptionsAccount{
  495.     public idException (String msg){
  496.     super(msg);
  497.     }
  498.    
  499.     public static void idException() throws exceptionsAccount{
  500.        
  501.     throw new exceptionsAccount  ("Id must be between 7-9 digit  ");
  502.     }
  503.  
  504. }
  505. ==============================================================================
  506. package bank;
  507.  
  508. public interface loanable {
  509.     boolean isThereIsLoan();     // function that using to Check if there  is a loan in  Student Account
  510.     boolean getLoan(double loan,int payment); //Open loan true only if customer don't have loan
  511.     void closeLoan();             //function that using to closing each loan payments left or part of them
  512.     String loanReturnByMonth(); // function that using to show loan details (loan value now, payment value left,   payments)
  513.     int getLoanPaymentLeft();// function that using to get loan payment left
  514.  
  515. }
  516. ==========================================================================================
  517. package bank;
  518.  
  519. import java.util.InputMismatchException;
  520.  
  521. public class loanFunctionOnAble extends Account implements loanable {
  522.         //------------------------------------------------------------
  523.        
  524.         protected double loan;
  525.         protected int payment;
  526.         protected int loanPaymentLeft;//save how many  payments left
  527.         protected double paymentValue;
  528.        
  529.         //-----------------------------------------------------------
  530.         public loanFunctionOnAble(String name, int id, int age) throws exceptionsAccount {
  531.             super(name, id, age);
  532.             // TODO Auto-generated constructor stub
  533.         }
  534.  
  535.         public void setPayment(int payment) {
  536.           this.payment = payment;
  537.        }
  538.  
  539.         @Override
  540.         public void closeLoan() {
  541.  
  542.              if (this.balanc<=this.loan){
  543.           try{
  544.                this.loan=this.balanc-this.loan;
  545.                this.balanc-=this.loan;
  546.                System.out.println("client must paying "+Math.abs(this.loan)+"  NIS  to close the loan");
  547.               }
  548.          catch(InputMismatchException e){
  549.                System.out.println(e.getMessage());
  550.                 }
  551.  
  552.          catch(ArithmeticException e){
  553.                System.out.println(e.getMessage());
  554.  
  555.                 }
  556.       }
  557.              else{
  558.          try {
  559.              this.loan=this.balanc-this.loan;
  560.              this.balanc-=this.loan;
  561.              System.out.println("your loan is: " + Math.abs(this.loan));
  562.           }
  563.          catch(InputMismatchException e){
  564.               System.out.println(e.getMessage());
  565.           }
  566.          catch(ArithmeticException e){
  567.              System.out.println(e.getMessage());
  568.           }
  569.      }
  570.        }
  571.  
  572.         @Override
  573.         public int getLoanPaymentLeft() {
  574.             // TODO Auto-generated method stub
  575.  
  576.        
  577.        try{
  578.            loanPaymentLeft=(int) (Math.abs((this.loan)/this.paymentValue));
  579.            }
  580.         catch(InputMismatchException e){
  581.             System.out.println(e.getMessage());
  582.         }
  583.          catch(ArithmeticException e){
  584.             System.out.println(e.getMessage());
  585.              }
  586.  
  587.        return loanPaymentLeft;
  588.        }
  589.  
  590.         public String loanReturnByMonth() {
  591.  
  592.             return ("Account Number:"+ this.accountNumber +
  593.                     ", loan return by month is: "+
  594.                     + paymentValue +
  595.                     " loan payment left is: "+ getLoanPaymentLeft() +
  596.                     " , loan left is:"+ Math.abs(this.loan));
  597.      }
  598.  
  599.  
  600.  
  601.  
  602.         @Override
  603.         public boolean isThereIsLoan() {
  604.             // TODO Auto-generated method stub
  605.             if (this.loan>0){
  606.                 return true;
  607.             }
  608.             else
  609.             {
  610.                 return false;
  611.             }
  612.         //  boolean answer=(loan>0?  true:  false);
  613.         //  return answer;
  614.         }
  615.  
  616.         @Override
  617.         public boolean getLoan(double loan, int payment) {
  618.             // TODO Auto-generated method stub
  619.  
  620.               isThereIsLoan();
  621.               boolean answer;
  622.               if( isThereIsLoan()==true || loan>25000){
  623.              answer= false;
  624.  
  625.                }
  626.           else{
  627.  
  628.         this.loan=loan;
  629.         this.payment=payment;
  630.           answer= true;
  631.           try{
  632.  
  633.          this.paymentValue=(this.loan/this.payment);
  634.         }
  635.           catch(InputMismatchException e){
  636.               System.out.println(e.getMessage());
  637.          }
  638.           catch(ArithmeticException e){
  639.               System.out.println(e.getMessage());
  640.          }
  641.        }
  642.         return answer;
  643.       }
  644.  
  645.     }
  646.  
  647.  
  648. ===========================================================================
  649. package bank;
  650.  
  651. public class regular extends Account {
  652.  
  653.     public regular(String name, int id, int age) throws exceptionsAccount {
  654.         super(name, id, age);
  655.         regularCount+=1;
  656.         this.typeOfaccount="regular";
  657.         fee=0.005;
  658.         this.limit=3000;
  659.         this.accountNumber=Integer.parseInt("1" + id);
  660.        
  661.         if(age>18){
  662.             this.age=age;
  663.         }
  664.           else if(age<18) try {
  665.               ageExcepptions.ageExcepptionsRegular();
  666.               }
  667.               catch (exceptionsAccount e) {
  668.               System.out.println(e.getMessage());  
  669.               }
  670.            
  671.     }
  672. }
  673.  
  674.  
  675. =========================================================================
  676. package bank;
  677.  
  678. public class Soldier extends Account {
  679.  
  680.     public Soldier(String name, int id, int age) throws exceptionsAccount {
  681.         super(name, id, age);
  682.         this.soldierCount+=1;
  683.         this.age=age;
  684.            fee=0.001;
  685.            this.typeOfaccount="Soldier";  
  686.            this.accountNumber=Integer.parseInt("5" + id);
  687.            this.limit=3000;
  688.         if(age>18){
  689.             this.age=age;
  690.         }
  691.         else
  692.               ageExcepptions.ageExcepptionsSoldier();
  693.     }
  694.  
  695. }
  696. ==============================================================================
  697. package bank;
  698.  
  699. import java.util.InputMismatchException;
  700.  
  701. public class Student extends loanFunctionOnAble  {
  702. public Student(String name, int id, int age ) throws exceptionsAccount {
  703.         super(name, id, age);
  704.         this.studentCount+=1;
  705.         this.age=age;
  706.            fee=0.001;
  707.            this.loan=0;
  708.            this.payment=0;
  709.            this.typeOfaccount="Student";  
  710.            this.accountNumber=Integer.parseInt("3" + id);
  711.            this.loanPaymentLeft=0;
  712.            this.paymentValue=0.00;
  713.            this.limit=5000;
  714.         if(age>18){
  715.             this.age=age;
  716.         }
  717.         else
  718.               ageExcepptions.ageExcepptionsStudent();
  719.        
  720.     }
  721. }
  722.  
  723.  
  724. ==========================================================================
  725. package bank;
  726.  
  727. public class Teenage extends Account {
  728.  
  729.     public Teenage(String name, int id, int age) throws exceptionsAccount {
  730.         super(name, id, age
  731.                 );
  732.         // TODO Auto-generated constructor stub
  733.         teenageCount+=1;
  734.         fee=0.00;
  735.         this.limit=1000;
  736.         this.accountNumber=Integer.parseInt("4" + id);
  737.         if(age<18){
  738.             this.age=age;
  739.         }
  740.           else
  741.               ageExcepptions.ageExcepptionsTeenage();
  742.              
  743.            
  744.    
  745.     }
  746.  
  747. }
  748. ======================================================================
  749. package bank;
  750.  
  751. public class withDrawException extends exceptionsAccount {
  752.     public withDrawException (String msg){
  753.     super(msg);
  754.     }
  755.    
  756.     public static void withDrawException() throws exceptionsAccount{
  757.        
  758.     throw new exceptionsAccount  ("you can with drow between 50 - ");
  759.     }
  760.  
  761. }
  762. =======================================================================
Advertisement
Add Comment
Please, Sign In to add comment