Advertisement
Dale_Scorcher

09_performancetask

Nov 28th, 2023
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.84 KB | Source Code | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class name_randomizer {
  5.  
  6.     /*
  7.         1, 2
  8.         1, 3
  9.         2, 1
  10.         2, 3
  11.         3, 1
  12.         3, 2
  13.  
  14.         There are 6 possible combinations.
  15.     */
  16.  
  17.     private static int[][] nameRandomizer = {
  18.         {1, 2},
  19.         {1, 3},
  20.         {2, 1},
  21.         {2, 3},
  22.         {3, 1},
  23.         {3, 2}
  24.     };
  25.  
  26.     private static int nameRandomizerMAX = 6;
  27.     private static int nameRandomizerVAL = 0;
  28.     private static String name01 = "null";
  29.     private static String name02 = "null";
  30.     private static String name03 = "null";
  31.  
  32.  
  33.     private static String name_result01;
  34.     private static String name_result02;
  35.     private static String name_result03;
  36.     private static String name_result04;
  37.     private static String name_result05;
  38.     private static String name_result06;
  39.  
  40.     private static String name_result01LOWERCASE;
  41.     private static String name_result02LOWERCASE;
  42.     private static String name_result03LOWERCASE;
  43.     private static String name_result04LOWERCASE;
  44.     private static String name_result05LOWERCASE;
  45.     private static String name_result06LOWERCASE;
  46.  
  47.     private static String name_result01ABBR;
  48.     private static String name_result02ABBR;
  49.     private static String name_result03ABBR;
  50.     private static String name_result04ABBR;
  51.     private static String name_result05ABBR;
  52.     private static String name_result06ABBR;
  53.  
  54.     public static void generator_name() {
  55.  
  56.         switch (nameRandomizerVAL) {
  57.             case 1:
  58.                 System.out.print(name01);
  59.                 break;
  60.             case 2:
  61.                 System.out.print(name02);
  62.                 break;
  63.             case 3:
  64.                 System.out.print(name03);
  65.                 break;
  66.             default:
  67.                 System.out.println("Error generator_name(): No valid switch case");
  68.  
  69.         }
  70.  
  71.  
  72.     }
  73.  
  74.     public static void array_cycle() {
  75.         for (int a = 0; a < nameRandomizerMAX; a++) {
  76.  
  77.             switch (a) {
  78.                 case 0:
  79.                     name_result01 = name01.concat(" " + name02);
  80.                     name_result01ABBR = String.valueOf(name01.charAt(0))+String.valueOf(name02.charAt(0));
  81.                     name_result01LOWERCASE = name_result01.toLowerCase();
  82.                     name_result01LOWERCASE = name_result01LOWERCASE.replace(' ', '_');
  83.                     break;
  84.                 case 1:
  85.                     name_result02 = name01.concat(" " + name03);
  86.                     name_result02ABBR = String.valueOf(name01.charAt(0))+String.valueOf(name03.charAt(0));
  87.                     name_result02LOWERCASE = name_result02.toLowerCase();
  88.                     name_result02LOWERCASE = name_result02LOWERCASE.replace(' ', '_');
  89.                     break;
  90.                 case 2:
  91.                     name_result03 = name02.concat(" " + name01);
  92.                     name_result03ABBR = String.valueOf(name02.charAt(0))+String.valueOf(name01.charAt(0));
  93.                     name_result03LOWERCASE = name_result03.toLowerCase();
  94.                     name_result03LOWERCASE = name_result03LOWERCASE.replace(' ', '_');
  95.                     break;
  96.                 case 3:
  97.                     name_result04 = name02.concat(" " + name03);
  98.                     name_result04ABBR = String.valueOf(name02.charAt(0))+String.valueOf(name03.charAt(0));
  99.                     name_result04LOWERCASE = name_result04.toLowerCase();
  100.                     name_result04LOWERCASE = name_result04LOWERCASE.replace(' ', '_');
  101.                     break;
  102.                 case 4:
  103.                     name_result05 = name03.concat(" " + name01);
  104.                     name_result05ABBR = String.valueOf(name03.charAt(0))+String.valueOf(name01.charAt(0));
  105.                     name_result05LOWERCASE = name_result05.toLowerCase();
  106.                     name_result05LOWERCASE = name_result05LOWERCASE.replace(' ', '_');
  107.                     break;
  108.                 case 5:
  109.                     name_result06 = name03.concat(" " + name02);
  110.                     name_result06ABBR = String.valueOf(name03.charAt(0))+String.valueOf(name02.charAt(0));
  111.                     name_result06LOWERCASE = name_result06.toLowerCase();
  112.                     name_result06LOWERCASE = name_result06LOWERCASE.replace(' ', '_');
  113.                     break;
  114.             }
  115.             for (int b = 0; b < 2; b++) {
  116.                 nameRandomizerVAL = nameRandomizer[a][b];
  117.                 if (b == 0) {
  118.                     System.out.print(a+1 + ". ");
  119.                 }
  120.  
  121.                 generator_name();
  122.  
  123.                 if (b == 1) {
  124.                     System.out.println("");
  125.                 } else if (b == 0) {
  126.                     System.out.print(" ");
  127.                 }
  128.             }
  129.         }
  130.     }
  131.  
  132.     public static void check_string(String check) {
  133.  
  134.         if (check.trim().isEmpty() == true) {
  135.             System.out.println("Error check_string: String is empty.");
  136.             System.exit(1);
  137.         }
  138.     }
  139.  
  140.     public static void printName (String name01, String name02, String name03) { //debug method, ignore.
  141.  
  142.         System.out.println(name01);
  143.         System.out.println(name02);
  144.         System.out.println(name03);
  145.  
  146.     }
  147.  
  148.     public static void main(String[] args) {
  149.         // Declare variables
  150.         Scanner input_name = new Scanner(System.in);
  151.         int max_names = 3;
  152.         int optionNameChosen = 0;
  153.  
  154.         System.out.println("<======== Name generator ========>");
  155.         System.out.println("Enter first three names: ");
  156.  
  157.         for (int i = 1; i <= max_names; i++) {
  158.             System.out.print(i + ": ");
  159.             if (input_name.hasNextLine()) {
  160.                 switch (i) {
  161.                     case 1:
  162.                         name01 = input_name.nextLine();
  163.                         check_string(name01);
  164.                         break;
  165.                     case 2:
  166.                         name02 = input_name.nextLine();
  167.                         check_string(name02);
  168.                         break;
  169.                     case 3:
  170.                         name03 = input_name.nextLine();
  171.                         check_string(name03);
  172.                         break;
  173.                     default:
  174.                         System.out.println("Error main: Switch iniator does not exist.");
  175.                 }
  176.             } else {
  177.                 System.out.println("Error main: Scanner has no line.");
  178.             }
  179.         }
  180.  
  181.         System.out.println("========");
  182.  
  183.         // Cycle through possibe combinations
  184.         array_cycle();
  185.  
  186.         // Ask the user which option
  187.  
  188.         Scanner optionName = new Scanner(System.in);
  189.         System.out.println("Which name combination would you like?");
  190.         System.out.print("Enter a value from 1 to " + nameRandomizerMAX + ": ");
  191.  
  192.         if (optionName.hasNextInt()) {
  193.             optionNameChosen = optionName.nextInt();
  194.         } else {
  195.             System.out.println("Error main: Input must be an integer within values 1 - " + nameRandomizerMAX);
  196.             System.exit(1);
  197.         }
  198.  
  199.         if (optionNameChosen < 0 || optionNameChosen > nameRandomizerMAX) {
  200.             System.out.println("Error main: Input must be an integer within values 1 - " + nameRandomizerMAX);
  201.             System.exit(1);
  202.         }
  203.  
  204.         switch (optionNameChosen) {
  205.             case 1:
  206.                 System.out.println("The initials for " + name_result01 + " is: " + name_result01ABBR );
  207.                 System.out.println("Suggested username: " + name_result01LOWERCASE);
  208.                 break;
  209.             case 2:
  210.                 System.out.println("The initials for " + name_result02 + " is: " + name_result02ABBR );
  211.                 System.out.println("Suggested username: " + name_result02LOWERCASE);
  212.                 break;
  213.             case 3:
  214.                 System.out.println("The initials for " + name_result03 + " is: " + name_result03ABBR );
  215.                 System.out.println("Suggested username: " + name_result03LOWERCASE);
  216.                 break;
  217.             case 4:
  218.                 System.out.println("The initials for " + name_result04 + " is: " + name_result04ABBR );
  219.                 System.out.println("Suggested username: " + name_result04LOWERCASE);
  220.                 break;
  221.             case 5:
  222.                 System.out.println("The initials for " + name_result05 + " is: " + name_result05ABBR );
  223.                 System.out.println("Suggested username: " + name_result05LOWERCASE);
  224.                 break;
  225.             case 6:
  226.                 System.out.println("The initials for " + name_result06 + " is: " + name_result06ABBR );
  227.                 System.out.println("Suggested username: " + name_result06LOWERCASE);
  228.                 break;
  229.             default:
  230.                 System.out.println("Error main: Invalid case");
  231.         }
  232.  
  233.  
  234.         input_name.close();
  235.         optionName.close();
  236.        
  237.  
  238.  
  239.     }
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement