Advertisement
marking2112

SoftUniCoursePlanning_Tech

Oct 26th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.96 KB | None | 0 0
  1. import java.util.*;
  2. public class SoftUniCoursePlanning {
  3.     public static void main(String[] args) {
  4.         Scanner scanner = new Scanner(System.in);
  5.  
  6.         List<String> course = new ArrayList<>(Arrays
  7.                 .asList(scanner.nextLine()
  8.                         .split(", ")));
  9.  
  10.         String line = scanner.nextLine();
  11.  
  12.         while (!"course start".equals(line)) {
  13.             String[] tokens = line.split(":");
  14.             String operation = tokens[0];
  15.             String lessonName = tokens[1];
  16.  
  17.             switch (operation) {
  18.                 case "Add":
  19.                     if (course.contains(lessonName)) {
  20.                         continue;
  21.                     } else {
  22.                         course.add(lessonName);
  23.                     }
  24.                     break;
  25.                 case "Insert":
  26.                     String index = tokens[2];
  27.                     if (!course.contains(lessonName)) {
  28.                         int position = Integer.parseInt(index);
  29.  
  30.                         if (position >= 0 && position < course.size()) {
  31.                             course.add(position, lessonName);
  32.                         }
  33.                     }
  34.                     break;
  35.                 case "Exercise":
  36.                     if (course.contains(lessonName)) {
  37.                         int position = course.indexOf(lessonName + 1);
  38.                         course.add(position, lessonName + "-Exercise");
  39.                     } else {
  40.                         course.add(lessonName);
  41.                         course.add(lessonName + "-Exercise");
  42.                     }
  43.                     break;
  44.                 case "Remove":
  45.                     course.remove(lessonName);
  46.                     break;
  47.                 case "Swap":
  48.                     String secondLesson = tokens[2];
  49.                     int position = course.indexOf(lessonName);
  50.                     int swapPosition = course.indexOf(secondLesson);
  51.  
  52.                     String exerciseLessonName = lessonName + "-Exercise";
  53.                     String exerciseSecondLesson = secondLesson + "-Exercise";
  54.  
  55.                     if (course.contains(lessonName) && course.contains(secondLesson)) {
  56.                         Collections.swap(course
  57.                                 , course.indexOf(lessonName)
  58.                                 , course.indexOf(secondLesson));
  59.                         if (course.contains(exerciseLessonName) && course.contains(exerciseSecondLesson)) {
  60.                             Collections.swap(course
  61.                                     , course.indexOf(exerciseLessonName)
  62.                                     , course.indexOf(exerciseSecondLesson));
  63.                         }
  64.                     }
  65.                     break;
  66.             }
  67.  
  68.  
  69.             line = scanner.nextLine();
  70.         }
  71.         for (int i = 0; i < course.size(); i++) {
  72.             int n = i + 1;
  73.             System.out.println(n + "." + course.get(i));
  74.         }
  75.  
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement