Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JavaFundamentals.FinalExamExamples;
- import JavaFundamentals.TextProcessingLab.Substring_03;
- import java.util.Scanner;
- public class ActivationKeys_01 {
- public static void main(String[] args) {
- Scanner read = new Scanner(System.in);
- // input will only contains : --> letters and numbers only split by : --> " >>> ".
- //StringBuilder probe = new StringBuilder(read.nextLine());
- String rowActivationKey = read.nextLine();
- String input = read.nextLine();
- StringBuilder inputManipulation = new StringBuilder(rowActivationKey);
- // we have all these commands :
- // --> Contains>>> : ( we must check if exist and print yes or no)
- // --> Flip>>>Upper/Lower>>>{startIndex}>>>{endIndex} : ( we have to change the word case of the given index)
- // !! end index is EXCLUSIVE !!
- // --> Slice>>>{startIndex}>>>{endIndex} : ( we have to remove the characters between the given index )
- // !! end index is EXCLUSIVE !!
- while (!input.equals("Generate")) {
- String[] command = input.split(">>>");
- String order = command[0];
- switch (order) {
- case "Contains":// check if it works !!
- String substring = command[1];
- if (!inputManipulation.toString().contains(substring)) {
- System.out.println("Substring not found!");
- } else {
- System.out.printf("%s contains %s%n", rowActivationKey, substring);
- }
- break;
- case "Flip":
- if (command[1].equals("Upper")) {//ok
- //StringBuilder toUpper = new StringBuilder(rowActivationKey);
- int startIndex = Integer.parseInt(command[2]);
- int endIndex = Integer.parseInt(command[3]);
- String temporary = inputManipulation.substring(startIndex,endIndex).toUpperCase();
- // create a temporary variable to use inputManipulation and change toUpperCase
- inputManipulation.replace(startIndex,endIndex,temporary);
- System.out.println(inputManipulation.toString());
- } else if (command[1].equals("Lower")) {//ok
- int startIndex = Integer.parseInt(command[2]);
- int endIndex = Integer.parseInt(command[3]);
- String temporary = inputManipulation.substring(startIndex,endIndex).toLowerCase();
- inputManipulation.replace(startIndex,endIndex,temporary);
- System.out.println(inputManipulation.toString());
- }
- break;
- case "Slice"://ok it works , DON'T TOUCH !!!!
- /*StringBuilder inputManipulation = new StringBuilder(rowActivationKey);*/
- int startIndex = Integer.parseInt(command[1]);
- int endIndex = Integer.parseInt(command[2]);
- inputManipulation.delete(startIndex, endIndex);
- System.out.println(inputManipulation.toString());
- break;
- }
- input = read.nextLine();
- }
- System.out.printf("Your activation key is: %s",inputManipulation.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement