Advertisement
petur_stoqnov

Warrior's Quest2

Mar 5th, 2020
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Warrior2 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String input = scanner.nextLine();
  8.  
  9. String command;
  10.  
  11. while (!"For Azeroth".equals(command = scanner.nextLine())) {
  12. String[] tokens = command.split("\\s+");
  13.  
  14. if ("GladiatorStance".equals(tokens[0])) {
  15. input = input.toUpperCase();
  16. System.out.println(input);
  17. } else if ("DefensiveStance".equals(tokens[0])) {
  18. input = input.toLowerCase();
  19. System.out.println(input);
  20. } else if ("Dispel".equals(tokens[0])) {
  21. int index = Integer.parseInt(tokens[1]);
  22. if (index >= 0 && index < input.length()) {
  23. //String letterToReplace = input.charAt(index) + "";
  24. String replacementLetter = tokens[2].charAt(0) + "";
  25. char findSymbol = replacementLetter.charAt(0);
  26. StringBuilder string = new StringBuilder(input);
  27. string.setCharAt(index, findSymbol);
  28. input = "";
  29. input += string;
  30. System.out.println("Success!");
  31. } else {
  32. System.out.println("Dispel too weak.");
  33. }
  34. } else if ("Target".equals(tokens[0]) && "Change".equals(tokens[1])) {
  35. String firstSubstring = tokens[2];
  36. String secondSubstring = tokens[3];
  37. if (input.contains(firstSubstring)) {
  38. input = input.replace(firstSubstring, secondSubstring);
  39. System.out.println(input);
  40. } else {
  41. break;
  42. }
  43. } else if ("Target".equals(tokens[0]) && "Remove".equals(tokens[1])) {
  44. StringBuilder builder = new StringBuilder(input);
  45. String target = tokens[2];
  46.  
  47. if (input.contains(target)) {
  48. int startIndex = input.indexOf(target);
  49. int stopIndex = startIndex + target.length();
  50.  
  51. builder.delete(startIndex, stopIndex);
  52. input = "" + builder;
  53.  
  54. System.out.println(input);
  55. } else {
  56. break;
  57. }
  58. } else {
  59. System.out.println("Command doesn't exist!");
  60. }
  61. }
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement