Advertisement
deyanmalinov

05. Robotics + TimeFormat

May 20th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.time.LocalTime;
  4. import java.time.format.DateTimeFormatter;
  5. import java.util.ArrayDeque;
  6. import java.util.Deque;
  7. import java.util.Scanner;
  8.  
  9. public class Main {
  10.     public static void main(String[] args){
  11.         Scanner scan = new Scanner(System.in);
  12.         String [] line = scan.nextLine().split(";");
  13.         String [] robots = new String[line.length];
  14.         int [] procTime = new int[line.length];
  15.         int [] workTime = new int[line.length];
  16.  
  17.         for (int i = 0; i < line.length; i++) {
  18.             String[] temp = line[i].split("-");
  19.             robots[i] = temp[0];
  20.             procTime[i] = Integer.parseInt(temp[1]);
  21.  
  22.         }
  23.         String startTime = scan.nextLine();
  24.  
  25.  
  26.  
  27.         Deque<String> products = new ArrayDeque<>();
  28.  
  29.         String end = scan.nextLine();
  30.  
  31.         while (!end.equals("End")){
  32.             products.offer(end);
  33.             end = scan.nextLine();
  34.         }
  35.         String [] timeData = startTime.split(":");
  36.         int hours = Integer.parseInt(timeData[0]);
  37.         int min = Integer.parseInt(timeData[1]);
  38.         int sec = Integer.parseInt(timeData[2]);
  39.        LocalTime time = LocalTime.of(hours, min,sec);
  40.  
  41.         while (!products.isEmpty()) {
  42.             time = time.plusSeconds(1);
  43.             String prod = products.poll();
  44.  
  45.             boolean isAssigned = false;
  46.             for (int i = 0; i < robots.length; i++) {
  47.                 if (workTime[i] == 0 && !isAssigned) {
  48.                     workTime[i] = procTime[i];
  49.                     isAssigned = true;
  50.                     printRobotData(robots[i], prod, time);
  51.                 }
  52.                 if (workTime[i] > 0) {
  53.                     workTime[i]--;
  54.                 }
  55.  
  56.             }
  57.             if (!isAssigned){
  58.                 products.offer(prod);
  59.             }
  60.         }
  61.  
  62.     }
  63.  
  64.     private static void printRobotData(String robot, String prod, LocalTime time) {
  65.         DateTimeFormatter form = DateTimeFormatter.ofPattern("HH:mm:ss");
  66.         System.out.println(robot + " - "+ prod + " [" + time.format(form) +"]");
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement