Question

Write a program that separately prompts the user for a first name and last name and outputs a string containing the following information, in order: a. First letter of the users name. b. First five letters of the users last name. c. A random two-digit integer You must construct the desired string ensuring all characters are lowercase; output the identification string accordingly. Assume the last name contains at least 5 characters. You must use the Random (java.util.Random) class to generate random numbers. As an example, input of Chris Alvin may result in calvin15.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

JAVA PROGRAM

import java.util.Random;
import java.util.Scanner;

class UserName
{

public static void main(String args[])
{
// declare variables
String fname,lname;
int n=0;
Scanner scr=new Scanner(System.in); // create Scanner object scr

System.out.print("Enter First Name: "); fname=scr.next(); // read First Name
System.out.print("Enter Last Name: "); lname=scr.next(); // read Last Name

Random rand=new Random(); // create Random object rand
// generate random 2 digit numbers
for(int i=10;i<=99;i++)
n=rand.nextInt(i);
// Extract first character from fname using charAt(0) and convert lowercase letter using toLowerCase()

// Extract first 5 letters from lname using substring
// and convert into lowercase letter using toLowerCase()
// after extract and convert the letters concatnation with random 2 digit number
String con=Character.toLowerCase(fname.charAt(0))+lname.substring(0,5).toLowerCase()+n;

System.out.println("User Name is: "+con); // display user name
}
}

OUTPUT

F:\>javac UserName.java

F:\>java UserName
Enter First Name: Chris
Enter Last Name: Alvin
User Name is: calvin61

F:\>java UserName
Enter First Name: Philips
Enter Last Name: Washington
User Name is: pwashi93

F:\>java UserName
Enter First Name: Robin
Enter Last Name: Michael
User Name is: rmicha83

F:\>java UserName
Enter First Name: Linda
Enter Last Name: Elizabeth
User Name is: leliza83

Add a comment
Know the answer?
Add Answer to:
Write a program that separately prompts the user for a first name and last name and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program that prompts the user for an input string with all lowercase letters....

    Write a C program that prompts the user for an input string with all lowercase letters. Your program should then sort the characters in the string and print the sorted string. Assume that the string contains no spaces and has at most 30 lowercase characters. Your program should loop continually until the user enters “q” to quit.

  • in a java application need  to create an application which prompts the user numerator and denominator values...

    in a java application need  to create an application which prompts the user numerator and denominator values then show the result of the division.  The application will use exception handling to verify the user has entered valid input and will continue to prompt the user for input as long as the value they enter is invalid.  Once the user has entered valid numerator and denominator values, the result is shown and the application exits. had some issues when I entered letters instead of...

  • Design a modular program using pseudo-code which prompts a user for their first name, followed by...

    Design a modular program using pseudo-code which prompts a user for their first name, followed by their last name; then displays a "Hello" salutation which concatenates their first name with their last name. Sample output (user input shown in red): Please enter your first name: John Please enter your last name: Smith Hello, John Smith! Your program must include a main module and one function; this function prompts the user for either their first name or last name, using a...

  • ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of...

    ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of a file. The program encoded sentences in the file and writes the encoded sentences to the output file. Enter the file name: messages.txt Output: encoded words are written to file: messages.txt.swt The program reads the content of the file and encodes a sentence by switching every alphabetical letter (lower case or upper case) with alphabetical position i, with the letter with alphabetical position 25...

  • Write a program that prompts a user, using Scanner, for 2 secret messages. Each message has...

    Write a program that prompts a user, using Scanner, for 2 secret messages. Each message has its own set of rules you need to use to decode it. You will use String methods to change the messages you receive from the user. *Note: Ensure that you make the changes in the order they are specified and do the operations on the updated String Sentence 1: Make everything after the first word lowercase Remove the last space Remove the first 3...

  • Using C Programming, Write a program that prompts for the user's first and last names. Declare a third array that will hold the user's last name and first name, separated by a comma and space....

    Using C Programming, Write a program that prompts for the user's first and last names. Declare a third array that will hold the user's last name and first name, separated by a comma and space. Use loops to inter through the names one character at a time, storing them into the full name array. Don't forget about the terminating character. Sample run: Enter your first name: john Enter your last name: matthews First name: John Last name: Matthews Full name:...

  • Design a Java program to reset a user's password. The password must consist of exactly six...

    Design a Java program to reset a user's password. The password must consist of exactly six characters, of which one must be a digit, one must be an uppercase letter, and one must be a lowercase letter. Tell the user if the password is correct or if incorrect tell them what is wrong with it. For example, you could say: "Not valid! the password must have 6 characters! Goodbye!" Can't contain loops. Using Boolean, String, Int, char

  • Write a program that prompts the user to enter a file name and displays the occurrences...

    Write a program that prompts the user to enter a file name and displays the occurrences of each letter in the file. Letters are case-insensitive. Here is a sample run: Enter a filename: Lincoln.txt Number of A’s: 23 Number of B’s: 0 Number of C’s: 12 …… Number of Y’s: 5 Number of Z’s: 7

  • Write a Java class named StringProcess that prompts the user to enter two non-empty strings and...

    Write a Java class named StringProcess that prompts the user to enter two non-empty strings and report the followings: 1) The length of the two strings 2) The ASCII value of the first letter in the first string 3) The ASCII value of the last letter in the second string 4) Whether the second string is a substring of the first string. Outputs: Your output should look similar as follows. Please enter the first string: Carrot Please enter the second...

  • Please help me with this program in Java: Write a Java program that prompts the user...

    Please help me with this program in Java: Write a Java program that prompts the user to enter a password that matches a specific pattern. Your program must approve the user's entry.. Here is the pattern, in this order: 1 or more upper case letters two lower case letters 1 or 2 digits zero or 1 upper case letters any two of this group @#$%^&

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT