import javax.swing.*; // A privileged aspect has access to the privite fields of any class, // yes, that's right. No reflection and no hypocrisy. privileged aspect secureGPA // securely change the GPA with a password { public void student.changeGPA(double gpa) { this.gpa = gpa; } private String student.password; // private within aspect, not student static String randomstring() // utility to generate random password { int n = (int)(Math.random()*5)+4; // random password length; String s = ""; for(;n>0;n--) s+=(char)( (int)(Math.random()*26)+97 ); //lower case return s; } // with advice you can change main without changing main... after(student s): execution(public student.new(..)) && target(s) { s.password = randomstring(); // generate random password JOptionPane.showMessageDialog(null, s.name+", Your password is "+s.password); } before(student s): call(void student.changeGPA(double)) && target(s) { String pswd = JOptionPane.showInputDialog(null, s.name+", Enter password to change your gpa: "); if (!s.password.equals(pswd)) throw new RuntimeException("Wrong password. Beware of motherhackers!"); } }//secureGPA // currently extendstudent advice has precedence over extendinterface aspect reorderaspects { declare precedence: secureGPA, *; // precedence over all other aspects }