public static void main(String[] args) {
		BufferedReader bufferReader = null;
		GridEngine gridEngine = null;
        List<Machine> machines = new ArrayList<>();

		try {
 
			String line;
 
			bufferReader = new BufferedReader(new FileReader("input.txt"));
			Machine machine = null;

			while ((line = bufferReader.readLine()) != null) {
				String[] commands = line.split("\\s");
				if (gridEngine == null) {
					gridEngine = new GridEngine(Integer.parseInt(commands[0]), Integer.parseInt(commands[1]));
				} else if (commands.length > 1) {
					machine = gridEngine.addMachine(Integer.parseInt(commands[0]), Integer.parseInt(commands[1]),
							Direction.toDirection(commands[2]));
                    machines.add(machine);
				} else if (machine != null) {
                    machine.recordMovements(commands[0], gridEngine);
				}
			}
        } catch (IOException e) {
			System.out.println("Error writing to file - " + e.getMessage());
		} catch (Exception e) {
			System.out.println("Error - " + e.getMessage());
		} finally {
			try {
				if (bufferReader != null)
					bufferReader.close();
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}

        List<Thread> threads = new ArrayList<>();
        for (Machine machine : machines) {
                Thread thread = new Thread(machine);
                thread.start();
                threads.add(thread);
        }

        createOutputFile(gridEngine, threads);
    }