Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java language 1. Create four integer constants for the following values o MIN UPPER 65 I/ min int value for an uppercase character, 65 is

Java language image text in transcribed
image text in transcribed
1. Create four integer constants for the following values o MIN UPPER 65 I/ min int value for an uppercase character, 65 is A o MIN-LOWER 97 // min int value for a lowercase daracter; 97 is o ALPHABET-LENGTH26 // there are 26 characters in the alphabet o PASSWORD LENGTH-S I/ desired length of passwords 2. Create a double constant for the following value PROBABILITY-UPPER-o.S // SO% probabity of upper-case O 3. Create a String variable to hold the password, and assign an empty String value to it. 4. 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 lke. o 5. For each desired password character, create a randomized int value for the character: Use the Random nextDouble method and the PROBABILITY UPPER constant to determine whether the character will be upper or lower case Use the Random nextint(int upperLimit) method using the ALPHABET LENGTH as the upper limit. This will give you a random number that will teill you how far into the alphabet your to-be-generated character is o o o 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 Concatenate the generated character to the password o o 6. 7. When you have generated all PASSWORD LENGTH characters, print the password 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. o oHINT: 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 o Prompt the user to enter the generated password o Read the input using the Scanner nextline0 method, and store it in an appropriately- typed variable Compare the input string to the generated password o If they match, exit the loop If they do not match, remain in the loop, and return to the "prompt" step - - 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: VbRIQ Please re-type your password: VbRIQ Congratulations! It's a match! BUILD SUCCESSFUL (total time: 9 seconds) run: Your new password: kDWSa 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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions