Advertisement
semsem_elazazy

Untitled

May 24th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.55 KB | None | 0 0
  1. package package1;
  2. import java.util.*;
  3. import java.io.*;
  4.  
  5. public class Account extends CheckAccount {
  6.    
  7.     ArrayList<Transactions> List2= new ArrayList<Transactions>();
  8.      
  9.     //Variables
  10.  
  11.     //protected String  date;
  12.     protected String name;
  13.     protected int Account_num;
  14.     protected double  AnuualInterestRate;
  15.      double  Balance;
  16.  
  17.     // constructors
  18.      public Account () {}
  19.  
  20.      public Account (String Date, String name, int Account_num, int Balance ,Double AnuualInterestRate) {
  21.          this.name=name;
  22.          this.AnuualInterestRate=AnuualInterestRate;
  23.          this.Balance=Balance;
  24.          this.Account_num=Account_num;
  25.  
  26.      }
  27.  
  28.      // getters and setters
  29.  
  30.     /*public String getDate() {
  31.         return date;
  32.     }
  33.     public void setDate() {
  34.         Scanner in = new Scanner(System.in);
  35.         System.out.println("Enter the Date ");
  36.         date = in.nextLine();
  37.         }
  38.         */
  39.     public String getName() {
  40.         return name;
  41.     }
  42.     public void setName() {
  43.         Scanner in = new Scanner(System.in);
  44.         System.out.println("Enter the Name  ");
  45.         name = in.nextLine();
  46.     }
  47.     public int getAccount_num() {
  48.         return Account_num;
  49.     }
  50.     public void setAccount_num() {
  51.         Scanner in = new Scanner(System.in);
  52.         System.out.println("Enter the Account Number  ");
  53.         Account_num = in.nextInt();
  54.     }
  55.     public double getAnuualInterestRate() {
  56.         return AnuualInterestRate;
  57.     }
  58.     public void setAnuualInterestRate() {
  59.         this.AnuualInterestRate =  AnuualInterestRate;
  60.     /*  Scanner in = new Scanner(System.in);
  61.         System.out.println("Enter the AnuualInterestRate  ");
  62.         AnuualInterestRate = in.nextDouble();*/
  63.     }
  64.     //input file
  65.    
  66.     /*void Balance () throws IOException {
  67.         File f= new File ("Balance.txt");
  68.         FileInputStream fis = new FileInputStream(f);
  69.         byte [] b = new byte [(int)f.length()];
  70.         Balance  = fis.read(b);
  71.        
  72.     }*/
  73.     public double getBalance()  {
  74.         /*FileOutputStream fos = new FileOutputStream("Balance.txt");
  75.        
  76.             fos.write("Balance.txt".getBytes());
  77.             fos.flush();*/
  78.         /*String s =new String (b);
  79.         System.out.println(s);
  80.         fis.close();*/
  81.         return Balance;
  82.     }
  83.    
  84.     public void setBalance()   {
  85.           Scanner in = new Scanner(System.in);
  86.             System.out.println("Enter the Balance  ");
  87.             Balance = in.nextDouble();
  88.        
  89.         //this.Balance = Balance ;
  90.        
  91.         /*String s =new String (b);
  92.         System.out.println(s);
  93.         fis.close();
  94.         /*Scanner in = new Scanner(System.in);
  95.         System.out.println("Enter the Balance  ");
  96.         Balance = in.nextDouble();*/
  97.         //FileInputStream fis = new FileInputStream("Yasmeen.txt");
  98.     }
  99.    
  100.     //Transactions Methods
  101.  
  102.     //1)withdraw
  103.      public double Withdrawal(double amount) {
  104.             if(Balance< amount) {
  105.                 System.out.println("Invalid Amount");
  106.             }
  107.             else if (amount > 8000) {
  108.                 System.out.println("Invalid");
  109.             }
  110.             else {
  111.                  Transactions t = new Transactions(new Date (), amount,'W');
  112.                  List2.add(t);
  113.  
  114.                 Balance -=amount;
  115.             }
  116.             return Balance;
  117.         }
  118.  
  119.      //2)deposit
  120.  
  121.      public double  Deposit(double amount) {
  122.          Transactions t = new Transactions(new Date (), amount,'D');
  123.          List2.add(t);
  124.             Balance += amount;
  125.             return Balance;
  126.         }
  127.  
  128.      //3)AnnualInterestRate
  129.      public double AnuualInterestRate() {
  130.         /* Transactions t = new Transactions(new Date (),'R');
  131.          List2.add(t);*/
  132.          Balance +=(Balance *0.015);
  133.             return Balance ;
  134.      }
  135.  
  136.  
  137.      //Display Methods
  138.  
  139.      //1) Transactions
  140.      /*void  DisplayTransactions() throws IOException {
  141.        
  142.          for(int  i=0 ; i<List2.size() ; i++) {
  143.              FileWriter myWriter = new FileWriter("outcome.txt");
  144.              myWriter.write(List2.get(i).date +"     "+List2.get(i).transaction +"                  " + List2.get(i).amount +"                     " +Balance );
  145.          
  146.          
  147.          
  148.          }
  149.      }*/
  150.          public void DisplayAccountInformation() {
  151.            
  152.     try {
  153.          FileWriter myWriter = new FileWriter("outcome.txt");
  154.          myWriter.write("Account Number  : "+Account_num );
  155.          myWriter.write("Current Balance : "+Balance );
  156.          myWriter.write("\n");
  157.          myWriter.write("------------------After Transaction------------------");
  158.          myWriter.write("       Date                     Type               Amount                New Balance");
  159.          for(int  i=0 ; i<List2.size() ; i++) {
  160.              myWriter.write(List2.get(i).date +"     "+List2.get(i).transaction +"                  " + List2.get(i).amount +"                     " +Balance );
  161.          }
  162.          
  163.          myWriter.close();
  164.           } catch (IOException e) {
  165.           System.out.println("An error occurred.");
  166.           e.printStackTrace();
  167.         }
  168.      
  169.  
  170.    
  171.      }
  172.          }
  173.  
  174.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement