Part One: Get a Valid First and Last Name ask the user for and read in their first and last name use a loop to validate the first name: it must be at least one character long and it must start with a letter use a loop to validate the last name: it must not contain any spaces Hint: use a nested loop. The outer loop will iterate until there is valid input. The inner loop will check each character in the String to see if any of them are whitespace. Part Two: Generate a Username generate a two-digit random number (i.e., a random number between 10 and 99, inclusive) create a username that is the following data concatenated: the first letter of their first name in lower case the first five characters of their last name in lower case; if the name is shorter than five characters, use the whole last name the two-digit number output the username to the user Additional Coding Requirements code should compile use existing methods in the String and other classes choose the best loop and conditional structure for the task write your program in a way that reduces duplicated or repeated code follow Java naming conventions for variables (lower camel case with no underscores)
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
Write a complete
Part One: Get a Valid First and Last Name
- ask the user for and read in their first and last name
- use a loop to validate the first name: it must be at least one character long and it must start with a letter
- use a loop to validate the last name: it must not contain any spaces
- Hint: use a nested loop. The outer loop will iterate until there is valid input. The inner loop will check each character in the String to see if any of them are whitespace.
Part Two: Generate a Username
- generate a two-digit random number (i.e., a random number between 10 and 99, inclusive)
- create a username that is the following data concatenated:
- the first letter of their first name in lower case
- the first five characters of their last name in lower case; if the name is shorter than five characters, use the whole last name
- the two-digit number
- output the username to the user
Additional Coding Requirements
- code should compile
- use existing methods in the String and other classes
- choose the best loop and conditional structure for the task
- write your program in a way that reduces duplicated or repeated code
- follow Java naming conventions for variables (lower camel case with no underscores)
Hints
- Use the Character.isLetter(char) and Character.isWhitespace(char) methods.
- Write code to focus on a single task at a time. Test that code and make sure it is working before moving onto another task. Note that the "tasks" don't necessarily line up with the "parts" of the assignment. For example you might write and test code to work on each of this individually:
- ask for and read in the first name
- use a loop to validate the first name
- get the lowercase first character of the first name
- ask for and read in the last name
- use the loop (or nested loops!) to validate the last name
- get the first five characters of the last name, in lowercase
- generate the random number
- concatenate all the pieces together
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images