Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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-LOWER97

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-LOWER97 // min int value for a lowercase character, 97 is O ALPHABET-LENGTH = 26 // there are 26 characters in the alphabet o PASSWORD LENGTH 5 // desired length of passwords 2. Create a double constant for the following value PROBABILITY UPPER-0.5 // 50% probability of upper-case character 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 like. o 5. For each desired password character, create a randomized int value for the character: o 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 tell you how far into the alphabet your to-be-generated character is 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 wil 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. When you have generated all PASSWORD LENGTH characters, print the password 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. o o 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 o o 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 to Expert-Tailored 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

Recommended Textbook for

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions