Advertisement
veronikaaa86

01. Activation Keys

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