Advertisement
Guest User

Task planner

a guest
Oct 27th, 2019
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.45 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class TaskPlanner {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String[] input = scanner.nextLine().split("\\s+");
  10.         List<String> task = new ArrayList<>();
  11.  
  12.         for (int i = 0; i < input.length; i++) {
  13.             task.add(input[i]);
  14.         }
  15.  
  16.         int completedCount = 0;
  17.         int droppedCount = 0;
  18.         String command = scanner.nextLine();
  19.         while (!command.equals("End")) {
  20.             String[] temp = command.split("\\s+");
  21.             String firstCommand = temp[0];
  22.  
  23.             if (firstCommand.equals("Complete")) {
  24.                 if (Integer.parseInt(temp[1]) >= 0 && Integer.parseInt(temp[1]) < task.size()) {
  25.                     task.set(Integer.parseInt(temp[1]), "0");
  26.                 }
  27.             }
  28.  
  29.             if (firstCommand.equals("Change")) {
  30.                 if (Integer.parseInt(temp[1]) >= 0 && Integer.parseInt(temp[1]) < task.size()) {
  31.                    
  32.                         task.set(Integer.parseInt(temp[1]), temp[2]);
  33.                    
  34.                 }
  35.             }
  36.  
  37.             if (firstCommand.equals("Drop")) {
  38.                 if (Integer.parseInt(temp[1]) >= 0 && Integer.parseInt(temp[1]) < task.size()) {
  39.                     task.set(Integer.parseInt(temp[1]), "-1");
  40.                 }
  41.             }
  42.  
  43.             if (firstCommand.equals("Count")) {
  44.                 droppedCount = 0;
  45.                 if (temp[1].equals("Dropped")) {
  46.                     for (String s : task) {
  47.                         if (s.equals("-1")) {
  48.                             droppedCount++;
  49.                         }
  50.                     }
  51.                     System.out.println(droppedCount);
  52.                 } else if (temp[1].equals("Completed")) {
  53.                     completedCount = 0;
  54.                     for (String s : task) {
  55.                         if (s.equals("0")) {
  56.                             completedCount++;
  57.                         }
  58.                     }
  59.                     System.out.println(completedCount);
  60.                 }
  61.             }
  62.  
  63.             command = scanner.nextLine();
  64.         }
  65.  
  66.  
  67.         if (!task.isEmpty()) {
  68.             for (String s : task) {
  69.                 if (!s.equals("-1") && !s.equals("0")) {
  70.                     System.out.print(s + " ");
  71.                 }
  72.  
  73.             }
  74.         }
  75.  
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement