Hello Subash!
Here is the solution for the question you are asking for, I solved it in procedural way but if you are among the one who prefer OOP style then you can still ask it for me cause I have solved it from both methods but here I am just going to leave procedural one....
//author:Manish Acharya
import java.util.Scanner;
import java.util.*;
public class idgenerator {
public static void main(String[] args) {
String small_name="", long_name="", new_small_name="", new_long_name="";
char lr='a', rl='b';
int k=0, compare=0;
String id, reverse="";
Scanner userinput = new Scanner(System.in);
System.out.println("Enter the first name:");
String first_name = userinput.nextLine();
System.out.println("Enter the last name:");
String last_name = userinput.nextLine();
System.out.println("Enter the PIN:");
String pin = userinput.nextLine();
System.out.println("Enter any number N:");
System.out.println("Note: The given number should be less than or equal to PIN in length:");
int number = userinput.nextInt();
//checking part
if(number<=pin.length()) {
if(first_name.length() < last_name.length()) {
small_name = first_name;
long_name = last_name;
}
else if(first_name.length() > last_name.length()) {
long_name = first_name;
small_name = last_name;
}
else if(first_name.length() == last_name.length()) {
compare = first_name.compareTo(last_name);
if(compare<0) {
small_name = first_name;
long_name = last_name;
System.out.println("yes");
}
else if(compare>0){
long_name = first_name;
small_name = last_name;
}
else {
System.out.println("They are same!");
}
}
else {
System.out.println("Caught an unknown error!");
}
}
else {
System.out.println("Invalid number entered!");
}
//lowercase to uppercase and vice versa
for(int i=0; i<small_name.length(); i++) {
char a = small_name.charAt(i);
if(a >= 97 && a <= 123)
{
a = Character.toUpperCase(a);
}
else if(a >= 65 && a <= 96)
{
a = Character.toLowerCase(a);
}
new_small_name = new_small_name + a;
}
for(int i=0; i<long_name.length(); i++) {
char a = long_name.charAt(i);
if(a >= 97 && a <= 123)
{
a = Character.toUpperCase(a);
}
else if(a >= 65 && a <= 96)
{
a = Character.toLowerCase(a);
}
new_long_name = new_long_name + a;
}
//getting number from left to right and vice versa
for(int j=0; j<number; j++) {
lr = pin.charAt(j);
}
for(int j=pin.length()-1; j>=0; j--) {
reverse = reverse + pin.charAt(j);
}
for(int j=0; j<number; j++) {
rl = reverse.charAt(j);
}
//printing out id
System.out.println("Your ID is:" + new_small_name.charAt(new_small_name.length()-1) + new_long_name + lr + rl);
}
}