Advertisement
Lyubohd

01. Warrior's Quest

Mar 26th, 2020
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         String string = scan.nextLine();
  7.  
  8.         String input = scan.nextLine();
  9.         while (!"For Azeroth".equals(input)) {
  10.             String[] tokens = input.split("\\s+");
  11.             String command = tokens[0];
  12.  
  13.             switch (command) {
  14.                 case "GladiatorStance":
  15.                     string = string.toUpperCase();
  16.                     System.out.println(string);
  17.                     break;
  18.                 case "DefensiveStance":
  19.                     string = string.toLowerCase();
  20.                     System.out.println(string);
  21.                     break;
  22.                 case "Dispel":
  23.                     int index = Integer.parseInt(tokens[1]);
  24.                     char letter = tokens[2].charAt(0);
  25.                     if (index >= 0 && index < string.length()) {
  26.                         StringBuilder sb = new StringBuilder(string);
  27.                         sb.setCharAt(index, letter);
  28.                         string = sb.toString();
  29.                         System.out.println("Success!");
  30.                     } else {
  31.                         System.out.println("Dispel too weak.");
  32.                     }
  33.                     break;
  34.                 case "Target":
  35.                     if ("Change".equals(tokens[1])) {
  36.                         String firstSubstr = tokens[2];
  37.                         String secondsSubstr = tokens[3];
  38.                         string = string.replace(firstSubstr, secondsSubstr);
  39.                         System.out.println(string);
  40.                     } else if ("Remove".equals(tokens[1])) {
  41.                         String substring = tokens[2];
  42.                         string = string.replace(substring, "");
  43.                         System.out.println(string);
  44.                     } else {
  45.                         System.out.println("Command doesn't exist!");
  46.                     }
  47.                     break;
  48.                 default:
  49.                     System.out.println("Command doesn't exist!");
  50.             }
  51.  
  52.             input = scan.nextLine();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement