Answer to Question #254546 in Java | JSP | JSF for Mike

Question #254546

Your task is to create a program that can achieve the above requirements when given the students surname, first name and three digit postfix through CMD arguements




Sample run 1:


java InClass01_task01 Kandjeke Jenifer 003


Output: Good day Jenifer welcome to NUST.


Your email address is : jkandjeke@students.nust.na


Student number : KJEJEN003


Sample run 2:


java InClass01_task01 Kavezemba Terry 001


Output: Good day Terry welcome to NUST.


Your email address is : tkavezemba@students.nust.na


Student number : KZATER001


1
Expert's answer
2021-10-21T14:23:02-0400


package nust;




public class NUST {


      public static void main(String[] args) {
         
        if (args.length < 2) {
            System.out.println("Invalid number");
            return;
        }
        String firstString = args[1]; 
        String lastString = args[0]; 
        String postfixString = args[2];
       
        int start_number = 0, end = lastString.length() - 1, mid = (lastString.length() % 2 == 0) ? lastString.length() / 2 : lastString.length() / 2;
        
        String number = lastString.charAt(start_number ) + "" + lastString.charAt(mid) + "" + lastString.charAt(end) + firstString.substring(0, 3)
                + postfixString;
        
        String email_given = firstString.charAt(0) + lastString + "@students.nust.na";
        System.out.println("Good day " + firstString + " welcome to NUST.");
        System.out.println("Your email address is : " + email_given.toLowerCase());
        System.out.println("Student number : " + number.toUpperCase());
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS