Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class WarriorQuest {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String string = scanner.nextLine();
  8. String line = scanner.nextLine();
  9.  
  10. while(!line.equals("For Azeroth")){
  11. String [] tokens = line.split(" ");
  12. String command = tokens[0];
  13. switch (command) {
  14.  
  15. case "GladiatorStance":
  16. string = string.toUpperCase();
  17. System.out.println(string);
  18. break;
  19. case "DefensiveStance":
  20. string = string.toLowerCase();
  21. System.out.println(string);
  22. break;
  23. case "Dispel":
  24. int index = Integer.parseInt(tokens[1]);
  25. String token2 = tokens[2];
  26. char ch = token2.charAt(0);
  27. if (index >= 0 & index < string.length()) {
  28. string = string.substring(0, index) + ch + string.substring(index + 1);
  29. System.out.println("Success!");
  30.  
  31. } else {
  32. System.out.println("Dispel too weak.");
  33. }
  34. break;
  35. case "Target":
  36. if (tokens[1].equals("Change")) {
  37. String toReplace = tokens[2];
  38. String replaceWith = tokens[3];
  39. string = string.replace(toReplace, replaceWith);
  40. System.out.println(string);
  41. }
  42. else if (tokens[1].equals("Remove")) {
  43. String remove = tokens[2];
  44. string = string.replaceAll(remove, "");
  45. System.out.println(string);
  46. }
  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. line = scanner.nextLine();
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement