import javax.swing.*; aspect secaspect { // an inter-type declaration private String base.password; private int base.count = 0; // count number of accesses before // password need to be changed. // new procedure to change password private void base.changepw() { String p = JOptionPane.showInputDialog(null, "Time to change password. Enter old password:"); if (this.password.equals(p)) password = JOptionPane.showInputDialog(null, "Enter new password:"); else { JOptionPane.showMessageDialog(null,"you're an impostor!!!"); throw new Error("call the FBI!"); } count = 0; // reset counter }//changepw // advice to set password when object is first created after(base B) : execution(base.new()) && target(B) { B.password = JOptionPane.showInputDialog(null, "Enter a password and keep it secret: "); } // advice to check/change password after 4 accesses to base object services before(base B) : call(public * base.*(..)) && !within(base) && target(B) { B.count++; if (B.count>3) B.changepw(); else // check password { String p = JOptionPane.showInputDialog(null, "Enter password:"); if (!B.password.equals(p)) { JOptionPane.showMessageDialog(null, "you're an impostor!!!"); return; } } } // before advice declare precedence: secaspect,*; //secaspect has precedence over all }//secaspect