/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.text.*;
class CabRecordReader {
boolean moreRecords;
Scanner in;
inputFile
= new File(inputPath
); in = new Scanner(inputFile);
in.useDelimiter(",\n");
moreRecords = true;
}
public boolean hasMoreRecords() {
moreRecords = in.hasNext();
return moreRecords;
}
public String getNextRecord
() { moreRecords = in.hasNext();
if(moreRecords) {
line = in.next();
return line;
} else {
return null;
}
}
}
class CabRecordProcessor /* implements CabRecord*/ {
CabRecordReader reader;
RecordType recType;
double recValue;
double recGalCost;
public CabRecordProcessor
(String inputPath,
String outputPath
) { try {
reader = new CabRecordReader(inputPath);
System.
err.
println("File not Found..."); e.printStackTrace();
}
output = outputPath;
}
public void readFullRecord() {
try {
recDate = formatter.parse(reader.getNextRecord());
recID = reader.getNextRecord();
recType = RecordType.valueOf(reader.getNextRecord());
recValue
= Double.
parseDouble(reader.
getNextRecord()); if(recType == RecordType.valueOf("GAS")) {
recGalCost
= Double.
parseDouble(reader.
getNextRecord()); }
System.
err.
println("Error with the Date on " + recID
); e.printStackTrace();
System.
err.
println("Error with the Type on " + recID
); e.printStackTrace();
System.
err.
println("Getting this for some reason at " + recID
); e.printStackTrace();
}
}
public boolean butWait() {
return reader.hasMoreRecords();
}
public RecordType getType() {
return recType;
}
return recDate;
}
return recID;
}
public double getValue() {
return recValue;
}
public double getPerGallonCost() {
return recGalCost;
}
}
enum RecordType {
GAS, SERVICE, FARE
}
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
ArrayList<String> cabIDs = new ArrayList<String>();
ArrayList<Date> dates = new ArrayList<Date>();
ArrayList<RecordType> types = new ArrayList<RecordType>();
ArrayList<Double> values = new ArrayList<Double>();
ArrayList<Double> gasCosts = new ArrayList<Double>();
int tracker = 0;
CabRecordProcessor processor = new CabRecordProcessor(inputPath, outputPath);
while(processor.butWait()) {
processor.readFullRecord();
cabIDs.add(processor.getCabId());
dates.add(processor.getDate());
types.add(processor.getType());
values.add(processor.getValue());
if(processor.getType() == RecordType.valueOf("GAS")) {
gasCosts.add(tracker,processor.getPerGallonCost());
}
tracker++;
}
}
}