Advertisement
veronikaaa86

01. Activation Keys

Jul 30th, 2022
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. package examPrep2;
  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 inputLine = scanner.nextLine();
  12. while (!inputLine.equals("Generate")) {
  13. String[] tokens = inputLine.split(">>>");
  14.  
  15. String command = tokens[0];
  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. if (upperOrLower.equals("Upper")) {
  34. activationKey = activationKey.replace(substring, substring.toUpperCase());
  35. } else if (upperOrLower.equals("Lower")) {
  36. activationKey = activationKey.replace(substring, substring.toLowerCase());
  37. }
  38. System.out.println(activationKey);
  39.  
  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.  
  48. System.out.println(activationKey);
  49.  
  50. break;
  51. }
  52.  
  53. inputLine = scanner.nextLine();
  54. }
  55.  
  56. System.out.printf("Your activation key is: %s%n", activationKey);
  57. }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement