Advertisement
Semerkosa

Warrior's quest

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