/**
* 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;
while (againPlease){
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]+$");
if (nameMatch == false){
System.out.println("\nInvalid input!");
}
}while(nameMatch == false);
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);
int index = name.indexOf(" ");
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));
}
}
System.out.println("\nTo create another username, press 1. Press any other key to exit.");
int proceed = sc.nextInt();
if (proceed != 1){
againPlease = false;
}
}
System.exit(0);
}
}
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.