Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use Java Language. Thank you! TASK You are working in a large organization, in an IT department. Your employer has asked you to build a
Use Java Language. Thank you!
TASK You are working in a large organization, in an IT department. Your employer has asked you to build a password generator to provide long randomized passwords for the company's more secure systems. As an initial prototype, you have been asked to show the functionality with short generated strings, to show a proof-of-concept. For this prototype, your password-generation software should do the following: . Produce a 5-character string consisting of randomized uppercase and lowercase characters. - Each character should have a 50% probability of being uppercase, and a 50% probability of being lowercase which can be achieved by generating a random Boolean value of true or false. Prompt the user to re-type the generated password until they produce a correct copy of the password. USEFUL CODE FOR THIS TASK The Random class will generate random numbers - Declare a variable of the Random class in the same way you declare a Scanner variable: - Random ranVariable = new Random(); (and include an import for java.util. Random) - Get a random integer using the nextInt (int upperLimit) method. - The nextInt method generates an integer in the range from O up to (but not including) the upperLimit value - Get a random boolean value using the nextBoolean() method. - The nextBoolean method returns a true or false value with a probability of 50% each. Characters are associated with integer values in the Java character encoding - These characters are equivalent to the ASCII character encoding for the familiar Latin alphabet - Upper-case characters 'A' to 'Z' are represented by integers in the range 65-90, where 'A' is 65 and 'Z' is 90 - Lower-case characters 'a' to 'z' are represented by integers in the range 97-122, where 'a' is 97 and 'z' is 122 - See http://www.asciitable.com/ (look at the Dec and Chr columns) for examples - Use typecasting to convert an integer value to its char equivalent - int myint - 66; // We want this to become the character 'B' - char ryCha-(char) y Inti // Converts the integer 66 into the char value 'B' Building a String from nothing, by concatenating characters - You will want to build the generated password string by concatenating 5 characters together. - If you start by declaring a simple String variable for the password, with no volue assigned, you will get an error in NetBeans for trying to add characters to a non-existent String value - Instead, assign an empty String value using two" "double-quote characters with nothing between them. This creates a String value that contains no characters, and NetBeans will allow you to concatenate characters to it. INSTRUCTIONS 1. Create a new NetBeans project called Lab5. 2. Create four integer class-level constants for the following values: - MIN_UPPER = 65 / min int value for an uppercase character; 65 is 'A' - MIN_LOWER = 97 // min int value for a lowercase character; 97 is 'a' - ALPHABET_LENGTH = 26 // there are 26 characters in the alphabet - PASSWORD_LENGTH = 5 // desired length of passwords 3. First, you need to create one character and test whether you are getting the correct range of values and the correct character conversion: - Use the Random nextBoolean() method to determine whether the character will be upper or lower case. If the value is true, then that is an upper case character, otherwise it is a lower case character. - Use the Random nextInt (int upperLimit) method using the ALPHABET_LENGTH as the upper limit. This will give you a random number that will tell you how far into the alphabet your to-be-generated character is - Add MIN_UPPER or MIN_LOWER to your generated integer value, depending on whether you need an upper or lower case character. This will give you the integer value that represents your character. - Use typecasting to convert the generated integer to a char type. 4. Create a String variable to hold the password, and assign an empty String" value to it. 5. In order to generate a password of PASSWORD_LENGTH, you will want to repeat the character- generation for each character - Before you start writing this code, think about what type of loop would work best for this, and what the loop-control structure should look like. - Inside the loop, concatenate the generated character to the password variable 6. When you have generated all PASSWORD_LENGTH characters, print the password Sample output at this stage: Note that this is randomly generated - your output will be different! run: Your new password: JFhbb BUILD SUCCESSFUL (total time: 0 seconds) 7. Next, you want to repeat the logic associated with the user typing in the password until they enter a password that matches. - Before you starting to write this code, think about what type of loop would work best for this, and what the loop-control structure should look like. - HINT: Use a boolean variable to control your loop. This variable will represent whether or not the user has successfully entered the password. For example: set the value to false to start with (i.e., the user has not been successful yet). When you detect a matching input string, change the value to true. You can then use this variable as the condition to remain in the loop (false) or exit the loop(true). 8. For each user attempt at typing the generated password, do the following: Prompt the user to enter the generated password Read the input using the Scanner nextLine() method, and store it in an appropriately- typed variable Compare the input string to the generated password ~ if they match, exit the loop ~ If they do not match, remain in the loop, and return to the "prompt" step HINT: to compare string values, use a String method firstString.equals(String secondString) which returns a Boolean result(true when they match, false otherwise) 9. When the user has successfully entered the password, print the success message. SAMPLE OUTPUT *** Note: your password values will be randomized, and will vary from the sample output *** run: Your new password: VRIQ Please re-type your password: VERIQ Congratulations! It's a match! BUILD SUCCESSFUL (total time: 9 seconds) run: Your new password: KDWS Please re-type your password: KDWSA Not a match. Please try again. Please re-type your password: KDWSa Congratulations! It's a match! BUILD SUCCESSFUL (total time: 19 seconds) run: Your new password: XpHlf Please re-type your password: xpHlf Not a match. Please try again. Please re-type your password: XpHIF Not a match. Please try again. Please re-type your password: XpHlf Congratulations! It's a match! BUILD SUCCESSFUL (total time: 31 seconds)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started