-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTXTReader.java
36 lines (31 loc) · 1.2 KB
/
TXTReader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//-----------------------------------------------------
// Title: TXT Reader
// Author: Mahmut Emre Demir
// ID: 59344436266
// Section: 2
// Assignment: 4
// Description: This class reads the input file and processes the shipments accordingly.
//-----------------------------------------------------
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class TXTReader {
public void readTxtFile(File file) {
try (Scanner scanner = new Scanner(file)) {
// Reading the file line by line
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
// Splitting the line by spaces
String[] words = line.split("\\s+");
// Checking the first word to determine the operation
if (words[0].equals("schedule")) {
ShipmentTracking.scheduleShipment(new Shipment(words[1], Long.parseLong(words[2]), Long.parseLong(words[3])));
} else {
ShipmentTracking.runTime(Long.parseLong(words[1]));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}