starting foreach
People have troubles coming up with random passwords, so some companies are trying to help by generating random passwords for them. A good random password should appear "pronounceable", that is, one could attempt to read it as if it was a real word.
In this assignment we will create pronounceable random passwords by coming up with words that do not have two vowels or two consonants in a row. Consider for example:
WUZE REGOL DIDUGO QUGEBUT PIBEMAMA
You are asked to write a program, RandomPasswords
, that generates such random passwords of various lengths. Start by writing pseudocode for an algorithm that follows the specifications below.
When you have persuaded yourself that you have a well-defined and correct plan, move on to writing java code.
Write a method, generateRandomPassword()
, that takes as input an integer n
, and produces a word consisting of random letters so that:
The word has length n
, and has a vowel in every even location, but never in an odd location. See the example above.
The main()
method should call the generateRandomPassword()
to produce random words with lengths between 4 and 8 letters, as in the example above.
Only the main() method is static
. Every other method must not be. Which means, that you need to use a dummy object named RandomPasswords
in main().
alphabet
that contains all the capital letters of the English alphabet, such as:
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
.
Pick a random character from alphabet
. (The Random
class should be used here)
How can you make sure the random character you chose is a vowel? (Or a consonant?) Use a loop keep to keep choosing a random character until you find one that is a vowel. (Similarly for choosing a consonant.)
In defining the method generateRandomPassword()
you MUST use the predicate helper methods that we saw in class: isVowel()
and isEven()
.
@author
and @version
tags. Top of the method javadoc should include values for the @param
and @return
tags as needed.Submit the following files (only):
RandomPasswords.java
file, andTestingRandomPasswords.txt
Use the JUnit test fileRandomPasswordsTest.java code we provide here.