in the title is an error for my array. What does it mean????
ALSO How do i parse the file to remove all the junk at the end like the ENTER ENTER ENTER spaces... (it's like carriage returned a few times, empty lines.. I have NO idea what those are called... they definitely aren't white space..)
EDIT: I'm going to sleep now. I'll wake up early and try to fix it with the help I get. Thank you everyone!
while (scanner1.hasNextLine() && scanner2.hasNextLine())
{
String line1 = scanner1.nextLine();
String line2 = scanner2.nextLine();
// parse line1
String[] line1Tokens = line1.split(",");
// parse line2
String[] line2Tokens = line2.split(",");
// Print
String ticket = line1Tokens[0];
String arrived1 = line1Tokens[2];
String arrived2 = line1Tokens[3];
String pickup1 = line2Tokens[1];
String pickup2 = line2Tokens[2];
This is the whole method:
public static void merge(File file1, File file2) throws IOException
{
Scanner scanner1 = new Scanner(file1);
Scanner scanner2 = new Scanner(file2);
String trash = scanner1.nextLine();
String trash2 = scanner2.nextLine();
while (scanner1.hasNextLine() && scanner2.hasNextLine())
{
String line1 = scanner1.nextLine();
String line2 = scanner2.nextLine();
// parse line1
String[] line1Tokens = line1.split(",");
// parse line2
String[] line2Tokens = line2.split(",");
// Print
String ticket = line1Tokens[0];
String arrived1 = line1Tokens[2];
String arrived2 = line1Tokens[3];
String pickup1 = line2Tokens[1];
String pickup2 = line2Tokens[2];
System.out.println("Ticket: " + ticket + ", " +
"Arrived: " + arrived1 + ":" + arrived2 + " --- " +
"Pickup: " + pickup1 + ":" + pickup2 + " --- " +
"Cost: ");
}
}
Error I'm recieving:
Ticket: 1421, Arrived: 12:8 --- Pickup: 12:9 --- Cost:
Ticket: 1422, Arrived: 12:8 --- Pickup: 12:12 --- Cost:
Ticket: 1423, Arrived: 12:9 --- Pickup: 12:13 --- Cost:
Ticket: 1424, Arrived: 12:9 --- Pickup: 12:14 --- Cost:
Ticket: 1425, Arrived: 12:9 --- Pickup: 12:16 --- Cost:
Ticket: 1426, Arrived: 12:9 --- Pickup: 12:17 --- Cost:
Ticket: 1427, Arrived: 12:10 --- Pickup: 12:18 --- Cost:
Ticket: 1428, Arrived: 12:10 --- Pickup: 12:19 --- Cost:
Ticket: 1429, Arrived: 12:11 --- Pickup: 13:21 --- Cost:
Ticket: 1430, Arrived: 12:12 --- Pickup: 13:7 --- Cost:
Ticket: 1431, Arrived: 12:14 --- Pickup: 13:9 --- Cost:
Ticket: 1432, Arrived: 12:17 --- Pickup: 13:16 --- Cost:
Ticket: 1433, Arrived: 12:19 --- Pickup: 13:19 --- Cost:
Ticket: 1434, Arrived: 12:21 --- Pickup: 13:20 --- Cost:
java.lang.ArrayIndexOutOfBoundsException: 1
at ParkingLot.merge(ParkingLot.java:45)
at LotDriver.main(LotDriver.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
EDIT: So I started correcting it with all the information i've earned.
Here is my method code so far.
public static void merge(File file1, File file2) throws IOException
{
Scanner scanner1 = new Scanner(file1);
Scanner scanner2 = new Scanner(file2);
String trash = scanner1.nextLine();
String trash2 = scanner2.nextLine();
while (scanner1.hasNextLine() && scanner2.hasNextLine())
{
String line1 = scanner1.nextLine();
String line2 = scanner2.nextLine();
String ticket = "";
String arrived1 = "";
String arrived2 = "";
String pickup1 = "";
String pickup2 = "";
// parse line1
// String[] line1Tokens = line1.split(",");
// parse line2
// String[] line2Tokens = line2.split(",");
if (line1.contains(","))
{
String[] line1Tokens = line1.split(",");
// Print
ticket = line1Tokens[0];
arrived1 = line1Tokens[2];
arrived2 = line1Tokens[3];
}
if (line2.contains(","))
{
String[] line2Tokens = line2.split(",");
pickup1 = line2Tokens[1];
pickup2 = line2Tokens[2];
}
System.out.println("Ticket: " + ticket + ", " +
"Arrived: " + arrived1 + ":" + arrived2 + " --- " +
"Pickup: " + pickup1 + ":" + pickup2 + " --- " +
"Cost: ");
}
}
However, it's giving me an error still...
java.lang.ArrayIndexOutOfBoundsException: 1
at ParkingLot.merge(ParkingLot.java:45)
at LotDriver.main(LotDriver.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
Any help here? How do I set the array to solve for -1 everything?