Created
July 25, 2016 02:32
-
-
Save mlabisi/a615c80ca66dd5e1b1b708b868d337ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import java.util.ArrayList; | |
public class KeyCreator { | |
// Define the variables | |
private Random random = new Random(); | |
private int passwordLength; | |
private String password; | |
private ArrayList<Character> characters = new ArrayList<Character>(); | |
public KeyCreator(int length) { | |
// Initialize the variable | |
this.passwordLength = length; | |
this.random = new Random(); | |
this.password = ""; | |
this.characters = new ArrayList<Character>(); | |
} | |
public String createPassword() { | |
// write code that returns a randomized password | |
int i = 0; | |
this.password = ""; | |
while (i < this.passwordLength) { | |
int index = random.nextInt(25); | |
char symbol = "abcdefghijklmnopqrstuvwxyz".charAt(index); | |
this.characters.add(symbol); | |
i++; | |
} | |
for (Character letter : this.characters) { | |
this.password += letter; | |
} | |
this.characters.clear(); | |
return this.password; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Program { | |
public static void main(String[] args) { | |
PasswordRandomizer randomizer = new KeyCreator(13); | |
System.out.println("Password: " + randomizer.createPassword()); | |
System.out.println("Password: " + randomizer.createPassword()); | |
System.out.println("Password: " + randomizer.createPassword()); | |
System.out.println("Password: " + randomizer.createPassword()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment