public class SecuritySystem
{
private int failedAttempts; // Tracks consecutive failed attempts
private boolean isLocked; // true if the system is locked out
/**
* Simulates a biometric scan (e.g., fingerprint or retina).
* Returns true if the scan is verified, false otherwise.
*/
public boolean checkBiometric()
{ /* implementation not shown */ }
/**
* Processes an access attempt using the provided code.
* Updates the system state and returns true if access is granted,
* false otherwise, as described in part (a).
*/
public boolean attemptAccess(String code)
{ /* to be implemented in part (a) */ }
/**
* Processes a stream of codes separated by spaces.
* Calls attemptAccess for each code and returns the total number
* of successful accesses, as described in part (b).
* Precondition: codeStream contains at least one code and ends with a space.
*/
public int processLog(String codeStream)
{ /* to be implemented in part (b) */ }
/* There may be instance variables, constructors, and methods
that are not shown. */
}Example 1
| Method Call | checkBiometric() Returns | Return Value | System State After Call |
|---|---|---|---|
| attemptAccess("1234") | false | false | failedAttempts = 1, isLocked = false |
| attemptAccess("5678") | false | false | failedAttempts = 2, isLocked = false |
| attemptAccess("9999") | true | true | failedAttempts = 0, isLocked = false |
Example 2
| Method Call | checkBiometric() Returns | Return Value | System State After Call |
|---|---|---|---|
| attemptAccess("0000") | false | false | failedAttempts = 3, isLocked = true |
| attemptAccess("1111") | (not called) | false | failedAttempts = 3, isLocked = true |
| attemptAccess("ADMIN_RESET") | (not called) | true | failedAttempts = 0, isLocked = false |
/** * Processes an access attempt using the provided code. * Updates the system state and returns true if access is granted, * false otherwise, as described in part (a). */ public boolean attemptAccess(String code)
Example 1
| Method Call | Return Value |
|---|---|
| processLog("1111 2222 ADMIN_RESET 3333 ") | 1 |
Example 2
| Method Call | Return Value |
|---|---|
| processLog("A1 B2 C3 ") | 3 |
/** * Processes a stream of codes separated by spaces. * Calls attemptAccess for each code and returns the total number * of successful accesses, as described in part (b). * Precondition: codeStream contains at least one code and ends with a space. */ public int processLog(String codeStream)