Advertisement
SotirovG

ActivationKeys_01

Mar 30th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.48 KB | None | 0 0
  1. package JavaFundamentals.FinalExamExamples;
  2.  
  3. import JavaFundamentals.TextProcessingLab.Substring_03;
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class ActivationKeys_01 {
  8.     public static void main(String[] args) {
  9.         Scanner read = new Scanner(System.in);
  10.  
  11.         // input will only contains : -->  letters and numbers only split by : --> " >>> ".
  12.         //StringBuilder probe = new StringBuilder(read.nextLine());
  13.         String rowActivationKey = read.nextLine();
  14.         String input = read.nextLine();
  15.  
  16.         StringBuilder inputManipulation = new StringBuilder(rowActivationKey);
  17.         // we have all these commands :
  18.         //  --> Contains>>> : ( we must check if exist and print yes or no)
  19.         //  --> Flip>>>Upper/Lower>>>{startIndex}>>>{endIndex} : ( we have to change the word case of the given index)
  20.         //                                        !! end index is EXCLUSIVE !!
  21.         //  --> Slice>>>{startIndex}>>>{endIndex} : ( we have to remove the characters between the given index )
  22.         //                          !!  end index is EXCLUSIVE !!
  23.  
  24.         while (!input.equals("Generate")) {
  25.  
  26.             String[] command = input.split(">>>");
  27.             String order = command[0];
  28.  
  29.             switch (order) {
  30.                 case "Contains":// check if it works !!
  31.                     String substring = command[1];
  32.                     if (!inputManipulation.toString().contains(substring)) {
  33.                         System.out.println("Substring not found!");
  34.                     } else {
  35.                         System.out.printf("%s contains %s%n", rowActivationKey, substring);
  36.                     }
  37.                     break;
  38.                 case "Flip":
  39.                     if (command[1].equals("Upper")) {//ok
  40.                         //StringBuilder toUpper = new StringBuilder(rowActivationKey);
  41.                         int startIndex = Integer.parseInt(command[2]);
  42.                         int endIndex = Integer.parseInt(command[3]);
  43.                         String temporary = inputManipulation.substring(startIndex,endIndex).toUpperCase();
  44.                         // create a temporary variable to use inputManipulation and change toUpperCase
  45.                         inputManipulation.replace(startIndex,endIndex,temporary);
  46.  
  47.                         System.out.println(inputManipulation.toString());
  48.  
  49.  
  50.                     } else if (command[1].equals("Lower")) {//ok
  51.                         int startIndex = Integer.parseInt(command[2]);
  52.                         int endIndex = Integer.parseInt(command[3]);
  53.                         String temporary = inputManipulation.substring(startIndex,endIndex).toLowerCase();
  54.                         inputManipulation.replace(startIndex,endIndex,temporary);
  55.  
  56.                         System.out.println(inputManipulation.toString());
  57.  
  58.                     }
  59.                     break;
  60.                 case "Slice"://ok it works , DON'T TOUCH !!!!
  61.                     /*StringBuilder inputManipulation = new StringBuilder(rowActivationKey);*/
  62.                     int startIndex = Integer.parseInt(command[1]);
  63.                     int endIndex = Integer.parseInt(command[2]);
  64.                     inputManipulation.delete(startIndex, endIndex);
  65.  
  66.                     System.out.println(inputManipulation.toString());
  67.                     break;
  68.  
  69.             }
  70.  
  71.  
  72.             input = read.nextLine();
  73.         }
  74.  
  75.  
  76.         System.out.printf("Your activation key is: %s",inputManipulation.toString());
  77.  
  78.  
  79.     }
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement