Advertisement
semsem_elazazy

Untitled

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