it is due in 24 hours. Please read the pdf and follow the exact instructions. Do not use complex code, stick to the code it asks to use. Please use netbeans
ISM3230In-class Lab Module 5 – Loop Logic Spring 2021
FOCUS TOPICS
• Looping logic
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.
o 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.
o 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)
o Get a random integer using the nextInt(int upperLimit) method.
▪ The nextInt method generates an integer in the range from 0 up to (but not
including) the upperLimit value
o 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
o 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
o See http://www.asciitable.com/ (look at the Dec and Chr columns) for examples
o Use typecasting to convert an integer value to its char equivalent:
▪ int myInt = 66; // We want this to become the character ‘B’
▪ char myChar = (char) myInt; // Converts the integer 66 into the char value ‘B’
http://www.asciitable.com/
• Building a String from nothing, by concatenating characters
o You will want to build the generated password string by concatenating 5 characters
together.
o If you start by declaring a simple String variable for the password, with no value assigned,
you will get an error in NetBeans for trying to add characters to a non-existent String value
o 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.
o See the last few slides of the 3c_stringVariablesAndValues for an example.
INSTRUCTIONS
1. Create four integer class-level constants for the following values:
o MIN_UPPER = 65 // min int value for an uppercase character; 65 is ‘A’
o MIN_LOWER = 97 // min int value for a lowercase character; 97 is ‘a’
o ALPHABET_LENGTH = 26 // there are 26 characters in the alphabet
o PASSWORD_LENGTH = 5 // desired length of passwords
2. First, you need to create one character and test whether you are getting the correct range of
values and the correct character conversion:
o 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.
o 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 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.
o Use typecasting to convert the generated integer to a char type.
Checkpoint 1:
Print the following values to the screen:
1. The Boolean random variable, which should print true or false
2. The result of the nextInt random integer method, which should print a number
from 0 to ALPHABET_LENGTH – 1
3. The ASCII code of the character which is the result of the previously generated
random number from checkpoint step 2 plus either the MIN_UPPER or
MIN_LOWER, depending on the value of the random Boolean from checkpoint
step 1.
4. The converted character that has been obtained by casting the above integer
from checkpoint step 3 into a character type value.
Run the code multiple times (many times) to check that you are getting the
characters in the expected range. if you see empty squares or strange looking
symbols, your math may be incorrect; check your random generating code carefully.
Since the boolean is true, we
add 65 to 15 to make an upper P
Since the boolean is false, we
add 97 to 2 to make an lower c
Examples of incorrect math resulting in the characters being out of range:
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
o 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 Inside the loop, concatenate the generated character to the password variable
5. 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!
Unprintable character, appears blank
Character out of desired range
6. Next, you want to repeat the logic associated with the user typing in the password until they
enter a password that matches.
o 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 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).
7. 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 nextLine() method, and store it in an appropriately-
typed variable
o 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).
8. 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 ***
We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.
Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.
Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.
Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.
Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.
Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.
We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.
Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.
You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.
Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.
Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.
You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.
You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.
Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.
We create perfect papers according to the guidelines.
We seamlessly edit out errors from your papers.
We thoroughly read your final draft to identify errors.
Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!
Dedication. Quality. Commitment. Punctuality
Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.
We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.
We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.
We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.
We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.