Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class name_randomizer {
- /*
- 1, 2
- 1, 3
- 2, 1
- 2, 3
- 3, 1
- 3, 2
- There are 6 possible combinations.
- */
- private static int[][] nameRandomizer = {
- {1, 2},
- {1, 3},
- {2, 1},
- {2, 3},
- {3, 1},
- {3, 2}
- };
- private static int nameRandomizerMAX = 6;
- private static int nameRandomizerVAL = 0;
- private static String name01 = "null";
- private static String name02 = "null";
- private static String name03 = "null";
- private static String name_result01;
- private static String name_result02;
- private static String name_result03;
- private static String name_result04;
- private static String name_result05;
- private static String name_result06;
- private static String name_result01LOWERCASE;
- private static String name_result02LOWERCASE;
- private static String name_result03LOWERCASE;
- private static String name_result04LOWERCASE;
- private static String name_result05LOWERCASE;
- private static String name_result06LOWERCASE;
- private static String name_result01ABBR;
- private static String name_result02ABBR;
- private static String name_result03ABBR;
- private static String name_result04ABBR;
- private static String name_result05ABBR;
- private static String name_result06ABBR;
- public static void generator_name() {
- switch (nameRandomizerVAL) {
- case 1:
- System.out.print(name01);
- break;
- case 2:
- System.out.print(name02);
- break;
- case 3:
- System.out.print(name03);
- break;
- default:
- System.out.println("Error generator_name(): No valid switch case");
- }
- }
- public static void array_cycle() {
- for (int a = 0; a < nameRandomizerMAX; a++) {
- switch (a) {
- case 0:
- name_result01 = name01.concat(" " + name02);
- name_result01ABBR = String.valueOf(name01.charAt(0))+String.valueOf(name02.charAt(0));
- name_result01LOWERCASE = name_result01.toLowerCase();
- name_result01LOWERCASE = name_result01LOWERCASE.replace(' ', '_');
- break;
- case 1:
- name_result02 = name01.concat(" " + name03);
- name_result02ABBR = String.valueOf(name01.charAt(0))+String.valueOf(name03.charAt(0));
- name_result02LOWERCASE = name_result02.toLowerCase();
- name_result02LOWERCASE = name_result02LOWERCASE.replace(' ', '_');
- break;
- case 2:
- name_result03 = name02.concat(" " + name01);
- name_result03ABBR = String.valueOf(name02.charAt(0))+String.valueOf(name01.charAt(0));
- name_result03LOWERCASE = name_result03.toLowerCase();
- name_result03LOWERCASE = name_result03LOWERCASE.replace(' ', '_');
- break;
- case 3:
- name_result04 = name02.concat(" " + name03);
- name_result04ABBR = String.valueOf(name02.charAt(0))+String.valueOf(name03.charAt(0));
- name_result04LOWERCASE = name_result04.toLowerCase();
- name_result04LOWERCASE = name_result04LOWERCASE.replace(' ', '_');
- break;
- case 4:
- name_result05 = name03.concat(" " + name01);
- name_result05ABBR = String.valueOf(name03.charAt(0))+String.valueOf(name01.charAt(0));
- name_result05LOWERCASE = name_result05.toLowerCase();
- name_result05LOWERCASE = name_result05LOWERCASE.replace(' ', '_');
- break;
- case 5:
- name_result06 = name03.concat(" " + name02);
- name_result06ABBR = String.valueOf(name03.charAt(0))+String.valueOf(name02.charAt(0));
- name_result06LOWERCASE = name_result06.toLowerCase();
- name_result06LOWERCASE = name_result06LOWERCASE.replace(' ', '_');
- break;
- }
- for (int b = 0; b < 2; b++) {
- nameRandomizerVAL = nameRandomizer[a][b];
- if (b == 0) {
- System.out.print(a+1 + ". ");
- }
- generator_name();
- if (b == 1) {
- System.out.println("");
- } else if (b == 0) {
- System.out.print(" ");
- }
- }
- }
- }
- public static void check_string(String check) {
- if (check.trim().isEmpty() == true) {
- System.out.println("Error check_string: String is empty.");
- System.exit(1);
- }
- }
- public static void printName (String name01, String name02, String name03) { //debug method, ignore.
- System.out.println(name01);
- System.out.println(name02);
- System.out.println(name03);
- }
- public static void main(String[] args) {
- // Declare variables
- Scanner input_name = new Scanner(System.in);
- int max_names = 3;
- int optionNameChosen = 0;
- System.out.println("<======== Name generator ========>");
- System.out.println("Enter first three names: ");
- for (int i = 1; i <= max_names; i++) {
- System.out.print(i + ": ");
- if (input_name.hasNextLine()) {
- switch (i) {
- case 1:
- name01 = input_name.nextLine();
- check_string(name01);
- break;
- case 2:
- name02 = input_name.nextLine();
- check_string(name02);
- break;
- case 3:
- name03 = input_name.nextLine();
- check_string(name03);
- break;
- default:
- System.out.println("Error main: Switch iniator does not exist.");
- }
- } else {
- System.out.println("Error main: Scanner has no line.");
- }
- }
- System.out.println("========");
- // Cycle through possibe combinations
- array_cycle();
- // Ask the user which option
- Scanner optionName = new Scanner(System.in);
- System.out.println("Which name combination would you like?");
- System.out.print("Enter a value from 1 to " + nameRandomizerMAX + ": ");
- if (optionName.hasNextInt()) {
- optionNameChosen = optionName.nextInt();
- } else {
- System.out.println("Error main: Input must be an integer within values 1 - " + nameRandomizerMAX);
- System.exit(1);
- }
- if (optionNameChosen < 0 || optionNameChosen > nameRandomizerMAX) {
- System.out.println("Error main: Input must be an integer within values 1 - " + nameRandomizerMAX);
- System.exit(1);
- }
- switch (optionNameChosen) {
- case 1:
- System.out.println("The initials for " + name_result01 + " is: " + name_result01ABBR );
- System.out.println("Suggested username: " + name_result01LOWERCASE);
- break;
- case 2:
- System.out.println("The initials for " + name_result02 + " is: " + name_result02ABBR );
- System.out.println("Suggested username: " + name_result02LOWERCASE);
- break;
- case 3:
- System.out.println("The initials for " + name_result03 + " is: " + name_result03ABBR );
- System.out.println("Suggested username: " + name_result03LOWERCASE);
- break;
- case 4:
- System.out.println("The initials for " + name_result04 + " is: " + name_result04ABBR );
- System.out.println("Suggested username: " + name_result04LOWERCASE);
- break;
- case 5:
- System.out.println("The initials for " + name_result05 + " is: " + name_result05ABBR );
- System.out.println("Suggested username: " + name_result05LOWERCASE);
- break;
- case 6:
- System.out.println("The initials for " + name_result06 + " is: " + name_result06ABBR );
- System.out.println("Suggested username: " + name_result06LOWERCASE);
- break;
- default:
- System.out.println("Error main: Invalid case");
- }
- input_name.close();
- optionName.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement