Java Reference
In-Depth Information
As previously discussed, methods that are used to help an object accomplish
its tasks and are not intended to be called by other programs commonly are
referred to as helper methods and are made private. Using the private access
specifier makes the method available only to methods within the class. Two such
helper methods are in the Password class: the verifyFormat() method and the
encrypt() method.
The verifyFormat() method has the task of verifying that the password value
provided is within the established rules as acceptable for passwords in the
Password class. Figure 9-35 displays the pseudocode that outlines the logic for
the verifyFormat() method. Figure 9-36 displays the code for the verifyFormat()
method of the Password class.
verifyFormat() method
(no return data; parameter is String: entered password)
Begin
Set number found to false
If password is empty string
Throw Exception: no password provided
End If
If password length < minimum size
Throw Exception: password < minimum size
End If
If password length > maximum size
Throw Exception: password > maximum size
End If
Loop through all characters in password or until numeric is found
If character at current index of password is a digit
Set number found to true
End If
End Loop
If number found is false
throw Exception: password invalid - no numeric digit
End If
End
FIGURE 9-35
The verifyFormat() method receives a password from its caller as a String
parameter named pswd (line 199). Using the length() method of the String
provides the ability to verify that a password value was submitted and that it is
within the acceptable range for number of characters, with at least 6 characters
and no more than 15 characters. As shown in lines 203 and 204 of Figure 9-36, if
no password is supplied at all (a null, or zero-length, string), there is nothing to
Search WWH ::




Custom Search