Advertisement
veronikaaa86

01. Activation Keys

Nov 24th, 2021
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. package examPrepFinal;
  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. String command = tokens[0];
  15.  
  16. switch (command) {
  17. case "Contains":
  18. String substring = tokens[1];
  19.  
  20. if (activationKey.contains(substring)) {
  21. System.out.printf("%s contains %s%n", activationKey, substring);
  22. } else {
  23. System.out.println("Substring not found!");
  24. }
  25. break;
  26. case "Flip":
  27. String criteria = tokens[1];
  28. int startIndex = Integer.parseInt(tokens[2]);
  29. int endIndex = Integer.parseInt(tokens[3]);
  30. String substringToReplace = activationKey.substring(startIndex, endIndex);
  31.  
  32. if (criteria.equals("Upper")) {
  33. activationKey = activationKey.replace(substringToReplace,
  34. substringToReplace.toUpperCase());
  35. } else {
  36. activationKey = activationKey.replace(substringToReplace,
  37. substringToReplace.toLowerCase());
  38. }
  39.  
  40. System.out.println(activationKey);
  41. break;
  42. case "Slice":
  43. int start = Integer.parseInt(tokens[1]);
  44. int end = Integer.parseInt(tokens[2]);
  45.  
  46. String substringToRemove = activationKey.substring(start, end);
  47. activationKey = activationKey.replace(substringToRemove, "");
  48. System.out.println(activationKey);
  49. break;
  50. }
  51.  
  52. inputLine = scanner.nextLine();
  53. }
  54.  
  55. System.out.printf("Your activation key is: %s%n", activationKey);
  56. }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement