Advertisement
Didart

Activation Keys

Nov 24th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. import java.util.Locale;
  2. import java.util.Scanner;
  3.  
  4. public class ActivationKeys {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         String activationKey = scanner.nextLine();
  9.  
  10.         String input = scanner.nextLine();
  11.         while (!input.equals("Generate")) {
  12.  
  13.             String[] tokens = input.split(">>>");
  14.             String command = tokens[0];
  15.  
  16.             switch (command) {
  17.                 case "Contains":
  18.                     String substring = tokens[1];
  19.                     if (activationKey.contains(substring)) {
  20.                         System.out.printf("%s contains %s%n", activationKey, substring);
  21.                     } else {
  22.                         System.out.println("Substring not found!");
  23.                     }
  24.                     break;
  25.                 case "Flip":
  26.                     String criteria = tokens[1];
  27.                     int startIndex = Integer.parseInt(tokens[2]);
  28.                     int endIndex = Integer.parseInt(tokens[3]);
  29.                     String substringToReplace = activationKey.substring(startIndex, endIndex);
  30.  
  31.                     if (criteria.equals("Upper")) {
  32.                         activationKey = activationKey.replace(substringToReplace,
  33.                                 substringToReplace.toUpperCase(Locale.ROOT));
  34.                     } else {
  35.                         activationKey = activationKey.replace(substringToReplace,
  36.                                 substringToReplace.toLowerCase(Locale.ROOT));
  37.                     }
  38.                     System.out.println(activationKey);
  39.                     break;
  40.                 case "Slice":
  41.                     int start = Integer.parseInt(tokens[1]);
  42.                     int end = Integer.parseInt(tokens[2]);
  43.  
  44.                     String substringToRemove = activationKey.substring(start, end);
  45.                     activationKey = activationKey.replace(substringToRemove, "");
  46.                     System.out.println(activationKey);
  47.                     break;
  48.             }
  49.             input = scanner.nextLine();
  50.         }
  51.         System.out.printf("Your activation key is: %s%n", activationKey);
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement