Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class SoftUniCoursePlanning {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<String> course = new ArrayList<>(Arrays
- .asList(scanner.nextLine()
- .split(", ")));
- String line = scanner.nextLine();
- while (!"course start".equals(line)) {
- String[] tokens = line.split(":");
- String operation = tokens[0];
- String lessonName = tokens[1];
- switch (operation) {
- case "Add":
- if (course.contains(lessonName)) {
- continue;
- } else {
- course.add(lessonName);
- }
- break;
- case "Insert":
- String index = tokens[2];
- if (!course.contains(lessonName)) {
- int position = Integer.parseInt(index);
- if (position >= 0 && position < course.size()) {
- course.add(position, lessonName);
- }
- }
- break;
- case "Exercise":
- if (course.contains(lessonName)) {
- int position = course.indexOf(lessonName + 1);
- course.add(position, lessonName + "-Exercise");
- } else {
- course.add(lessonName);
- course.add(lessonName + "-Exercise");
- }
- break;
- case "Remove":
- course.remove(lessonName);
- break;
- case "Swap":
- String secondLesson = tokens[2];
- int position = course.indexOf(lessonName);
- int swapPosition = course.indexOf(secondLesson);
- String exerciseLessonName = lessonName + "-Exercise";
- String exerciseSecondLesson = secondLesson + "-Exercise";
- if (course.contains(lessonName) && course.contains(secondLesson)) {
- Collections.swap(course
- , course.indexOf(lessonName)
- , course.indexOf(secondLesson));
- if (course.contains(exerciseLessonName) && course.contains(exerciseSecondLesson)) {
- Collections.swap(course
- , course.indexOf(exerciseLessonName)
- , course.indexOf(exerciseSecondLesson));
- }
- }
- break;
- }
- line = scanner.nextLine();
- }
- for (int i = 0; i < course.size(); i++) {
- int n = i + 1;
- System.out.println(n + "." + course.get(i));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement