EA Username Generator

/** * EA username generator * @author Josh Wang * @version 09/12/17 */ import java.util.*; public class EAusername{ public static void main(String[] args){ boolean againPlease = true; boolean nameMatch; boolean jahreMatch; String name; String jahre; int index; Scanner sc = new Scanner(System.in); System.out.println(); do{ System.out.println("Input your full name."); name = sc.nextLine(); nameMatch = name.matches("^[ a-zA-Z]+$"); index = name.indexOf(" "); if (nameMatch == false || index < 0){ System.out.println("\nInvalid input!"); } }while(nameMatch == false || index < 0); System.out.println(); do{ System.out.println("Input your year of graduation."); jahre = sc.nextLine(); jahreMatch = jahre.matches("[0-9]+"); if (jahreMatch == false || jahre.length() != 4){ System.out.println("\nInvalid input!"); } }while (jahreMatch == false || jahre.length() != 4); String name1 = name.substring(0, index); name = name.substring(index+1); index = name.indexOf(" "); int finalLength; if (index < 0){ if (name.length() < 4){ finalLength = name.length(); } else{ finalLength = 4; } System.out.println("\n" + name.substring(0,finalLength) + name1.substring(0,1) + jahre.substring(2)); } else{ String name2 = name.substring(0, index); name = name.substring(index+1); index = name.indexOf(" "); if (index < 0){ if (name.length() < 4){ finalLength = name.length(); } else{ finalLength = 4; } System.out.println("\n" + name.substring(0,finalLength) + name1.substring(0,1) + name2.substring(0,1) + jahre.substring(2)); } else{ name = name.substring(index+1); if (name.length() < 4){ finalLength = name.length(); } else{ finalLength = 4; } System.out.println("\n" + name.substring(0,finalLength) + name1.substring(0,1) + name2.substring(0,1) + jahre.substring(2)); } } } }
Supports people with two to four names!

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.