Hadeel e

Hadeel e

  • NA
  • 50
  • 6.1k

aspectj program

Apr 26 2020 1:00 AM
I am learning aspectj and I have the following program:
  1. import org.aspectj.lang.JoinPoint;    
  2.     
  3.    privileged aspect newaccount    
  4.    {    
  5.        void around(account a, double x) : execution(void account.withdraw(double)) && target(a) && args(x){    
  6.            if(x < 0){    
  7.                System.out.println("trying to cheat!");    
  8.                return;    
  9.            }    
  10.            else if(x > a.balance){  
  11.                System.out.println("not enough money!");    
  12.                return;    
  13.            }  
  14.            proceed(a, x);    
  15.        }  
  16.        void around( account a, double x) : execution(void account.deposit(double)) && target(a) && args(x){  
  17.            if(x < 0){  
  18.                System.out.println("trying to deposit negtive money!");    
  19.                return;    
  20.            }    
  21.            proceed(x);    
  22.     }  
  23.        after(): execution(public static void *.main(String[])){  
  24.            account a3 = new account(3000,"he nerd");    
  25.            a3.withdraw(-100);    
  26.            a3.deposit(90);    
  27.            a3.printbalance();  
  28.        }  
  29.    }   
and I want to protect the account by adding a password as well as adding a charge fee when a withdraw lowers the balance below a certain minimum.

I also want to keep track of all the transactions made on an account.

How could I implement that?

I am compiling this program with an existing java program: 
  1. public class account  
  2. {  
  3.     private double balance;  
  4.     private String owner;   
  5.     public account(double x, String s) { balance=x; owner=s; }  
  6.     public String owner() { return owner; }  
  7.     public void withdraw(double a) { balance -= a; }  
  8.     public void deposit(double a) { balance += a; }  
  9.     public void printbalance() { System.out.println(balance); }  
  10.   
  11.     // main for testing:  
  12.   public static void main(String[] argv)  
  13.   {  
  14.       account a1 = new account(2000,"you boss");  
  15.       account a2 = new account(1000,"me nerd");  
  16.       a1.deposit(400);  
  17.       a2.withdraw(400);   // not enough money!  
  18.       a2.withdraw(300);  // trying to cheat!  
  19.       a1.printbalance();  
  20.       a2.printbalance();  
  21.   }//main  
  22. // account

I would appreciate your help. Thank you.