fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.*;
  7.  
  8.  
  9. class CabRecordReader {
  10. boolean moreRecords;
  11. File inputFile;
  12. Scanner in;
  13.  
  14. public CabRecordReader(String inputPath) throws FileNotFoundException {
  15. inputFile = new File(inputPath);
  16. in = new Scanner(inputFile);
  17. in.useDelimiter(",\n");
  18. moreRecords = true;
  19. }
  20.  
  21. public boolean hasMoreRecords() {
  22. moreRecords = in.hasNext();
  23. return moreRecords;
  24. }
  25. public String getNextRecord() {
  26. String line;
  27. moreRecords = in.hasNext();
  28. if(moreRecords) {
  29. line = in.next();
  30. return line;
  31. } else {
  32. return null;
  33. }
  34. }
  35. }
  36.  
  37. class CabRecordProcessor /* implements CabRecord*/ {
  38.  
  39. String output;
  40. CabRecordReader reader;
  41. RecordType recType;
  42. Date recDate;
  43. String recID;
  44. double recValue;
  45. double recGalCost;
  46.  
  47. SimpleDateFormat formatter = new SimpleDateFormat("yyyy/mm/dd");
  48.  
  49. public CabRecordProcessor(String inputPath, String outputPath) {
  50. try {
  51. reader = new CabRecordReader(inputPath);
  52. } catch (FileNotFoundException e) {
  53. System.err.println("File not Found...");
  54. e.printStackTrace();
  55. }
  56. output = outputPath;
  57. }
  58.  
  59. public void readFullRecord() {
  60. try {
  61. recDate = formatter.parse(reader.getNextRecord());
  62. recID = reader.getNextRecord();
  63. recType = RecordType.valueOf(reader.getNextRecord());
  64. recValue = Double.parseDouble(reader.getNextRecord());
  65. if(recType == RecordType.valueOf("GAS")) {
  66. recGalCost = Double.parseDouble(reader.getNextRecord());
  67. }
  68. } catch (ParseException e) {
  69. System.err.println("Error with the Date on " + recID);
  70. e.printStackTrace();
  71. System.err.println("Error with the Type on " + recID);
  72. e.printStackTrace();
  73. } catch (NullPointerException e) {
  74. System.err.println("Getting this for some reason at " + recID);
  75. e.printStackTrace();
  76. }
  77. }
  78.  
  79. public boolean butWait() {
  80. return reader.hasMoreRecords();
  81. }
  82.  
  83. public RecordType getType() {
  84. return recType;
  85. }
  86.  
  87. public Date getDate() {
  88. return recDate;
  89. }
  90.  
  91. public String getCabId() {
  92. return recID;
  93. }
  94.  
  95. public double getValue() {
  96. return recValue;
  97. }
  98.  
  99. public double getPerGallonCost() {
  100. return recGalCost;
  101. }
  102.  
  103. }
  104. enum RecordType {
  105. GAS, SERVICE, FARE
  106. }
  107.  
  108.  
  109. /* Name of the class has to be "Main" only if the class is public. */
  110. class Ideone
  111. {
  112. public static void main (String[] args) throws java.lang.Exception
  113. {
  114. ArrayList<String> cabIDs = new ArrayList<String>();
  115. ArrayList<Date> dates = new ArrayList<Date>();
  116. ArrayList<RecordType> types = new ArrayList<RecordType>();
  117. ArrayList<Double> values = new ArrayList<Double>();
  118. ArrayList<Double> gasCosts = new ArrayList<Double>();
  119.  
  120. int tracker = 0;
  121.  
  122. CabRecordProcessor processor = new CabRecordProcessor(inputPath, outputPath);
  123.  
  124. while(processor.butWait()) {
  125. processor.readFullRecord();
  126. cabIDs.add(processor.getCabId());
  127. dates.add(processor.getDate());
  128. types.add(processor.getType());
  129. values.add(processor.getValue());
  130. if(processor.getType() == RecordType.valueOf("GAS")) {
  131. gasCosts.add(tracker,processor.getPerGallonCost());
  132. }
  133. tracker++;
  134. }
  135. }
  136. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:123: error: cannot find symbol
    CabRecordProcessor processor = new CabRecordProcessor(inputPath, outputPath);
                                                          ^
  symbol:   variable inputPath
  location: class Ideone
Main.java:123: error: cannot find symbol
    CabRecordProcessor processor = new CabRecordProcessor(inputPath, outputPath);
                                                                     ^
  symbol:   variable outputPath
  location: class Ideone
2 errors
stdout
Standard output is empty