Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class MyClass {
- public static void main(String args[]) {
- Scanner scanner = new Scanner(System.in);
- String tourString = scanner.nextLine();
- String commandString = scanner.nextLine();
- while(true) {
- if (commandString.equals("Travel")) {
- System.out.printf("Ready for world tour! Planned stops: %s", tourString);
- break;
- } else {
- String[] commandWithParams = commandString.split(":");
- switch (commandWithParams[0]) {
- case "Add Stop" : System.out.println("IN ADD STOP");int index = Integer.parseInt(commandWithParams[1]); if (index <= tourString.length() && index >= 0) { tourString = tourString.substring(0, index)
- + commandWithParams[2]
- + tourString.substring(index, tourString.length());
- System.out.println(tourString);
- } break;
- case "Remove Stop" : System.out.println("IN 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);
- System.out.println(tourString);} break;
- case "Switch" : System.out.println("IN SWITCH"); if (tourString.contains(commandWithParams[1])) {tourString = tourString.replace(commandWithParams[1], commandWithParams[2]);
- System.out.println(tourString);
- } break;
- }
- }
- commandString = scanner.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement