Respuesta :

Answer:

import java.util.Scanner;

public class LabProgram {

   public static void main(String[] args) {

       Scanner scanner = new Scanner(System.in);

       String input = scanner.nextLine();

       // splits the input by spaces

       String[] inputArray = input.split(" ");

       // gets the first name from the inputArray

       // by accessing first element of array

       String firstName = inputArray[0];

       // gets the last name from the inputArray

       // by accessing second element of array

       String lastName = inputArray[1];

       // gets the number from the inputArray

       // by parsing String element as int

       int number = Integer.parseInt(inputArray[2]);

       // implementation of the login name generation

       String login = "";

       // adds first 5 letters of last name to login if last name >= 5 letters

       if (lastName.length() >= 5) {

           login += lastName.substring(0,5);

       } else { // adds entire last name if not

           login += lastName;

       }

       // adds first letter of first name to login

       login += firstName.substring(0,1);

       // gets the last two digits of the input number

       // using modulus operator and converting num to String

       login += Integer.toString(number % 100);

       // prints login name

       System.out.println("Your login name: " + login);

   }

}

Explanation:

The first part of this program takes an input from the user using the Scanner function. Then, it uses the .split() function to split the input String by spaces and adding each of the parts of the String as different elements to an array. The elements of this array are then accessed in turn and assigned to each value - firstName, lastName, and number. Keep in mind that each of the elements of the array is a String, so to get the number, the program has to parse the String as an Integer.

Next, this program implements the creation of the login. First, it adds the first 5 elements of the lastName string to the login String by using the .substring() function. It does the same thing for getting the first letter of the firstName. Getting the last 2 digits of the number is a bit more complicated.

Using the modulus operator gives you the remainder of a division function. So by doing % 100 on a 4-digit number, you get the remainder of the number as it's divided by 100, which is the last 2 digits of the number. Then, to add it to the login String, the program converts it back from an Integer to a String. Then, the login String is printed.

Note: I don't know all the requirements for this class so you may need to add/modify some things a bit, but this should do what is indicated in your post. If you have any clarifying questions about this code, feel free to ask!