Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement the class Security Agent described below. Instance variables. A securi

ID: 3840072 • Letter: I

Question

Implement the class Security Agent described below. Instance variables. A security agent is responsible for a particular door lock. Declare the necessary instance variables such that a SecurityAgent: I Remembers (stores) a Combination II Has access to this particular DoorLock, i.e. maintains a reference to a Door Lock object Implement a constructor with no parameter such that when a new Security Agent is created: I It creates a new Combination and stores it II It creates a new DoorLock with this saved Combination. For the sake of simplicity, you may decide to always use the same combination If secret is the name of the instance variable that is used to remember the Combination. Or, you can let your SecurityAgents use their imagination, so that each SecurityAgent has a new Combination that it only knows. Valid values must be in the range 1 to 10; Alternative way to generate a random combination Implement the instance method public DoorLock getDoorLock() that returns a reference to the saved DoorLock Implement the instance method public void enableDoorLock() that simply re-enable the particular DoorLock that this SecurityAgent is responsible for, with the saved secret Combination.

Explanation / Answer

DoorLock.java

package security;

public class DoorLock {

   Combination comb;
   public DoorLock(Combination c){
       comb=c;
   }
}

Combination.java

package security;

public class Combination {

   int combination;
   public Combination(int one,int two,int three,int four){
       String str=three+""+one+""+four+""+two;
       combination=Integer.parseInt(str);
   }
}

SecurityAgent.java

package security;

public class SecurityAgent {

   Combination comb;
   DoorLock door;
  
   public SecurityAgent(){
       int a=(int)(Math.random()*10)+1;
       int b=(int)(Math.random()*10)+1;
       int c=(int)(Math.random()*10)+1;
       int d=(int)(Math.random()*10)+1;
      
       comb=new Combination(a, b, c, d);
       door=new DoorLock(comb);
   }
  
   public DoorLock getDoorLock(){
       return door;
   }
  
  
}