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)

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section: Chapter Questions
Problem 9PP
icon
Related questions
Question

Write a complete program to generate a username based on a user's first and last name. 

Part One: Get a Valid First and Last Name 

  1. ask the user for and read in their first and last name
  2. use a loop to validate the first name: it must be at least one character long and it must start with a letter
  3. 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 

  1. generate a two-digit random number (i.e., a random number between 10 and 99, inclusive)
  2. 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
  3. 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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage