Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program that first defines three string objects called firstName, middle

ID: 3809684 • Letter: W

Question

write a program that first defines three string objects called firstName, middleName, and lastName which contains your own first, middle and last name separately. If you do not have middle name, then make up one. Then try to generate a new user name for you by using your first letter of your first name(captilized), first letter of you middle name (Captilized), plus all letters in your last name, add a random number between (1 to 100) to the your new user name. Here is an exampl: Name: John blake adams then the user name generated by your program coulde be: JBadams23

Explanation / Answer

Hi, Please find my implementation.

import java.util.Random;

import java.util.Scanner;

public class StringName{

  

   public static void main(String[] args) {

      

       String firstName, middleName, lastName;

      

       Scanner sc = new Scanner(System.in);

      

       System.out.print("Enter first name: ");

       firstName = sc.next();

      

       System.out.print("Enter middle name: ");

       middleName = sc.next();

      

       System.out.print("Enter last name: ");

       lastName = sc.next();

      

       Random random = new Random();

      

       String newName = "";

      

       newName = newName + Character.toUpperCase(firstName.charAt(0));

      

       newName = newName + Character.toUpperCase(middleName.charAt(0));

      

       newName = newName + lastName.toLowerCase();

      

       newName = newName + (random.nextInt(100)+1);

      

       System.out.println("New Name: "+newName);

   }  

  

}

/*

Smaple run:

Enter first name: John

Enter middle name: blake

Enter last name: adams

New Name: JBadams29

*/