Advertisement
mirena18uni

TaskPlanner

Feb 19th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 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.  
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. String[] values = scanner.nextLine().split("\\s+");
  11. List<Integer> hours = new ArrayList<>();
  12. int countCompleted=0;
  13. int countIncomplete=0;
  14. int countDropped=0;
  15.  
  16. for (int i = 0; i < values.length; i++) {
  17. hours.add(Integer.parseInt(values[i]));
  18. }
  19. String command = scanner.nextLine();
  20.  
  21. while (!command.equals("End")) {
  22. String[] operations = command.split("\\s+");
  23. if (operations[0].equals("Complete")) {
  24. int index = Integer.parseInt(operations[1]);
  25. if (index < hours.size()) {
  26. hours.set(index, 0);
  27. }
  28.  
  29. } else if (operations[0].equals("Change")) {
  30. int index = Integer.parseInt(operations[1]);
  31. int newHour = Integer.parseInt(operations[2]);
  32. if (index < hours.size()) {
  33. hours.set(index, newHour);
  34. }
  35.  
  36. } else if (operations[0].equals("Drop")) {
  37. int index = Integer.parseInt(operations[1]);
  38. if (index < hours.size()) {
  39. hours.set(index, -1);
  40. }
  41.  
  42. } else if (operations[1].equals("Completed")) {
  43. for (Integer hour : hours) {
  44. int count=0;
  45. if (hour == 0) {
  46. countCompleted++;
  47. }
  48. }
  49. System.out.printf("%d%n", countCompleted);
  50.  
  51.  
  52. } else if (operations[1].equals("Incomplete")) {
  53. for (Integer hour : hours) {
  54. int count=0;
  55. if (hour > 0) {
  56. countIncomplete++;
  57.  
  58. }
  59.  
  60. }
  61. System.out.printf("%d%n", countIncomplete);
  62.  
  63.  
  64. } else if (operations[1].equals("Dropped")) {
  65. for (Integer hour : hours) {
  66. int count=0;
  67. if (hour < 0) {
  68. countDropped++;
  69.  
  70. }
  71.  
  72. }
  73. System.out.printf("%d%n", countDropped);
  74. }
  75.  
  76.  
  77. command = scanner.nextLine();
  78. }
  79. for (Integer hour : hours) {
  80. if (hour > 0) {
  81. System.out.print(hour + " ");
  82. }
  83.  
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement