borovaneca

Hogwarts

Apr 3rd, 2023
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. package Hogwarts;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. public class Hogwarts {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
  10.  
  11.  
  12.         StringBuilder text = new StringBuilder(scanner.readLine());
  13.  
  14.  
  15.         String command;
  16.         while (!"Abracadabra".equals(command = scanner.readLine())) {
  17.             String[] tokens = command.split("\\s+");
  18.             String currentCommand = tokens[0];
  19.  
  20.             if (currentCommand.equals("Abjuration")) {
  21.                 text = new StringBuilder(text.toString().toUpperCase());
  22.                 System.out.println(text);
  23.  
  24.             } else if (currentCommand.equals("Necromancy")) {
  25.                 text = new StringBuilder(text.toString().toLowerCase());
  26.                 System.out.println(text);
  27.  
  28.             } else if (currentCommand.equals("Illusion")) {
  29.                 int index = Integer.parseInt(tokens[1]);
  30.                 if (index < 0 || index > text.length() - 1) {
  31.                     System.out.println("The spell was too weak.");
  32.  
  33.                 } else {
  34.                     text.replace(index, index + 1, tokens[2]);
  35.                     System.out.println("Done!");
  36.                 }
  37.  
  38.             } else if (currentCommand.equals("Divination")) {
  39.                 if (text.toString().contains(tokens[1])) {
  40.                     while (text.toString().contains(tokens[1])) {
  41.                         text = new StringBuilder(text.toString().replace(tokens[1], tokens[2]));
  42.                     }
  43.                     System.out.println(text);
  44.                 }
  45.  
  46.             } else if (currentCommand.equals("Alteration")) {
  47.                 if (text.toString().contains(tokens[1])) {
  48.                     text = new StringBuilder(text.toString().replace(tokens[1], ""));
  49.                     System.out.println(text);
  50.  
  51.                 }
  52.             } else {
  53.                 System.out.println("The spell did not work!");
  54.             }
  55.         }
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment