JAVA Write a class to manipulate a string made up of a perso
JAVA:
Write a class to manipulate a string made up of a person\'s first name, middle initial, and last name. The entire name has to be created as one field and not three separate fields. The entire name must also been created as a mixture of uppercase and lowercase letters which simply is not proper. Your goal is to output the three components of the name as separate fields with proper uppercase and lowercase letters.
Example:
Input: First Name Initial Last Name
JoHn J sMiTh
Output: John J Smith
Solution
Names.java
 import java.util.Scanner;
public class Names {
  
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println(\"Enter First Name Initial Last Name: \");
        String name = scan.nextLine();
        String firstName = name.split(\"\\\\s+\")[0];
        String initial = name.split(\"\\\\s+\")[1];
        String lastName = name.split(\"\\\\s+\")[2];
        String newFirstName = \"\", newInitial = \"\", newLastName = \"\";
        for(int i=0; i<firstName.length(); i++){
            if(i==0){
                newFirstName = String.valueOf(firstName.charAt(i)).toUpperCase();
            }
            else{
                newFirstName = newFirstName + String.valueOf(firstName.charAt(i)).toLowerCase();
            }
        }
        for(int i=0; i<initial.length(); i++){
            if(i==0){
                newInitial = String.valueOf(initial.charAt(i)).toUpperCase();
            }
            else{
                newInitial = newInitial + String.valueOf(initial.charAt(i)).toLowerCase();
            }
        }      
        for(int i=0; i<lastName.length(); i++){
            if(i==0){
                newLastName = String.valueOf(lastName.charAt(i)).toUpperCase();
            }
            else{
                newLastName = newLastName + String.valueOf(lastName.charAt(i)).toLowerCase();
            }
        }  
       
        System.out.println(\"Output: \"+newFirstName+\" \"+newInitial+\" \"+newLastName);
    }
}
Output:
Enter First Name Initial Last Name:
 JoHn J sMiTh
 Output: John J Smith


