Question

Assignment 2 Create a Java program called UserNames that reads the user's first and last name...

Assignment 2

Create a Java program called UserNames that reads the user's first and last name (separately), then prints a string composed of the first 4 letters of the user's last name, followed by the first letter of the user's first name, followed by a random number in the range of 10 to 99 (inclusive). You can assume the first name is at least one letter long and the last name is at least 4 letters. After doing this once, the program should ask the user if there is another user and then repeat if the answer is "y" or "Y". Otherwise, the program should end.

Additional Requirements
The name of your Java Class that contains the main method should be UserNames. All your code should be within the main method.
Your code should follow good coding practices, including good use of whitespace (indents and line breaks) and use of both inline and block comments.
You need to use meaningful identifier names that conform to standard Java naming conventions.

Homework Answers

Answer #1
SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

import java.util.Random;
import java.util.Scanner;
public class UserNames
{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // repeat
        while (true)
        {
            // Prompt for first name
            System.out.print("\nEnter your first name: ");
            String firstName = scanner.next();

            // prompt for last name
            System.out.print("Enter your last name: ");
            String lastName = scanner.next();

            Random random = new Random();
            String output = lastName.substring(0, 4) + firstName.charAt(0) + ((10 + random.nextInt(100)) % 100);
            System.out.println("The Output is: " + output);

            // ask if the user wants to repeat
            System.out.print("Do you want to continue...(y/n): ");
            char choice=scanner.next().charAt(0);
            if(choice=='y' || choice=='Y')
                continue;
            else
            {
                // STOP here
                System.out.println("Good Bye..!");
                break;
            }
        }
    }
}

=======================

SCREENSHOT:

OUTPUT:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a complete Java program which prompts the user of the program to input his/her first...
Write a complete Java program which prompts the user of the program to input his/her first name, then prompts the user for the middle initial and finally prompts the user for the last name. As indicated, there are three prompts to the user. The program should output the user’s name with the first name first, followed by the middle initial, and the last name last, all on one line (with appropriate spacing). If you could also pinpoint exactly where to...
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other The first letter A and the last letter O
Write a Java program that prompts the user to enter his/her name (first and last). Names...
Write a Java program that prompts the user to enter his/her name (first and last). Names are often expressed alphabetically as last name comma space first name. Display the user's alphabetical name and its length. Then output the user's initials. Finally, display the ASCII values of the initials with a space between them. Sample Output (input shown in italics) Enter your full name Jane Doe Your alphabetical name Doe, Jane is 9 characters long Your initials are JD ASCII of...
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other my name's Aya amro
Using NetBeans, create a Java program called Average.java. The program should use the Scanner class to...
Using NetBeans, create a Java program called Average.java. The program should use the Scanner class to get 4 integers from the user and store them in variables. The program should calculate the average of the 6 numbers as a floating point. Output all of the original input and the calculated average in the Command window. The code is expected to be commented and user-friendly.
Draw a timing diagram for the first four letters of your last name, given the following...
Draw a timing diagram for the first four letters of your last name, given the following specifications about the RS232 serial communications channel:           Baud rate:     115,200 baud           Data length: 8 bits           Parity:           None           Stop bits:      1 The first three letters of your last name should include at least one upper case letter and one or two lower case letters (If your last name is 3 letters or less, use first name). Indicate the bit time for...
11. First and Last Design a program that asks the user for a series of names...
11. First and Last Design a program that asks the user for a series of names (in no particular order). After the final person's name has been entered, the program should display the name that is first alphabetically and the name that is last alphabetically. For example, if the user enters the names Kristin, Joel, Adam, Beth, Zeb, and Chris, the program would display Adam and Zeb. I need help with creating a python code for this using a sentinel...
Python Jupyter Notebook Write a program that prompts the user to enter his/her first name, last...
Python Jupyter Notebook Write a program that prompts the user to enter his/her first name, last name, and year of birth in a single string (in the format: fn;ln;yyyy), then calculates the age tell it to him/her after greeting him/her using the first name. Make sure to capitalize the user's first name, regardless of how he/she typed it in. Hint: review Exercise 1! Example: Enter your first name, last name, and birth year (in format fn;ln;yyyy): alex;smith;1994 Hi Alex, you...
Below is the assignment, I have completed and tested every step except for the last one....
Below is the assignment, I have completed and tested every step except for the last one. "Print aLine with the first 'c' 'C' 'd' or 'D' removed." any help would be appreciated ASSIGNMENT Write a program using Scanner and its nextLine method. The following is an example of how to use nextLine Scanner kybd = new Scanner(System.in); System.out.println("Enter a line of text"); String aLine = kybd.nextLine(); If the user's input is shorter than 7 characters, print the message "The input...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT