3.2.2 Java OOPs - PasswordGenerator

The password generator will create a random password of a length from 5 to 8 characters long.

The passwords generated will not contain characters that can easily be confused.
Examples:  
  • O,0: uppercase o and zero; 
  • 1,l,I: one, lowercase L and uppercase i
Use the Java Random( ) class example below to see the syntax of the Random ( ) class

This class will not display any data

PasswordGenerator()Class

HAS-A: attributes -- All instance variables are private
    rn     a Random number generator    

RESPONDS-TO:
The constructor will start the random number generator

METHODS:
nextPassword( )
will return a password 5 to 8 characters long

nextLetter()
will return a random acceptable character for the password

Logic (Algorithm) for nextPassword()

In nextPassword()
  1. set the password to the empty string
  2. randomly set the length of the password from 5 to 8
  3. for the length of the password
    1. concatenate the nextLetter() to the password
  4. return the password

Logic (Algorithm) for the nextLetter()

In nextLetter()
  1. set the value of a string to all of the acceptable passwordCharacters
  2. extract a random nextLetter from the acceptable passwordCharacters
  3. return the nextLetter

Java Random() class Example


Comments