Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Hogwarts;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Hogwarts {
- public static void main(String[] args) throws IOException {
- BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
- StringBuilder text = new StringBuilder(scanner.readLine());
- String command;
- while (!"Abracadabra".equals(command = scanner.readLine())) {
- String[] tokens = command.split("\\s+");
- String currentCommand = tokens[0];
- if (currentCommand.equals("Abjuration")) {
- text = new StringBuilder(text.toString().toUpperCase());
- System.out.println(text);
- } else if (currentCommand.equals("Necromancy")) {
- text = new StringBuilder(text.toString().toLowerCase());
- System.out.println(text);
- } else if (currentCommand.equals("Illusion")) {
- int index = Integer.parseInt(tokens[1]);
- if (index < 0 || index > text.length() - 1) {
- System.out.println("The spell was too weak.");
- } else {
- text.replace(index, index + 1, tokens[2]);
- System.out.println("Done!");
- }
- } else if (currentCommand.equals("Divination")) {
- if (text.toString().contains(tokens[1])) {
- while (text.toString().contains(tokens[1])) {
- text = new StringBuilder(text.toString().replace(tokens[1], tokens[2]));
- }
- System.out.println(text);
- }
- } else if (currentCommand.equals("Alteration")) {
- if (text.toString().contains(tokens[1])) {
- text = new StringBuilder(text.toString().replace(tokens[1], ""));
- System.out.println(text);
- }
- } else {
- System.out.println("The spell did not work!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment