Advertisement
svephoto

Warrior's Quest [Java]

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