Advertisement
psi_mmobile

Untitled

Dec 3rd, 2022
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. import java.util.*;
  2. public class MyClass {
  3.     public static void main(String args[]) {
  4.         Scanner scanner = new Scanner(System.in);
  5.         String tourString = scanner.nextLine();
  6.         String commandString = scanner.nextLine();
  7.         while(true) {
  8.             if (commandString.equals("Travel")) {
  9.                 System.out.printf("Ready for world tour! Planned stops: %s", tourString);
  10.                 break;
  11.             } else {
  12.                 String[] commandWithParams = commandString.split(":");
  13.                 switch (commandWithParams[0]) {
  14.                     case "Add Stop" : int index = Integer.parseInt(commandWithParams[1]); if (index <= tourString.length() && index >= 0) { tourString = tourString.substring(0, index)
  15. + commandWithParams[2]
  16. + tourString.substring(index, tourString.length());
  17.                            
  18.                     } break;
  19. case "Remove Stop" : int beginIndex = Integer.parseInt(commandWithParams[1]); int endIndex = Integer.parseInt(commandWithParams[2]); if (beginIndex <= tourString.length() && beginIndex >= 0 && endIndex <= tourString.length() && endIndex >= 0) { tourString = tourString.substring(0,beginIndex) + tourString.substring(endIndex+1);
  20. } break;
  21. case "Switch" : if (tourString.contains(commandWithParams[1])) {tourString = tourString.replace(commandWithParams[1], commandWithParams[2]);
  22.  
  23. } break;
  24.                 }
  25.             }
  26.             System.out.println(tourString);
  27.             commandString = scanner.nextLine();
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement