/* Short sketch to fill in all of the missing dates from a year's data set */ String DatesFromFile[] = loadStrings("..\\dates.txt"); String TransactionsFromFile[] = loadStrings("..\\one year.txt"); String TempLine[]; // array to hold split data from Transaction File PrintWriter OutputFile = createWriter ("revised data.txt"); int numDates = DatesFromFile.length; int DateCounter; int TransactionCounter = 0; /* expected format of transaction data file: MM/DD/YYYY,PRICE MM/DD/YYYY,PRICE ... where PRICE is a positive floating point number */ /* To fill out the missing dates, we'll compare each date in the date list with each date found in the transaction file. Anytime the transaction file is missing a date, we'll write the date into the revised file with 0 for the PRICE to indicate that no transaction took place on that day. */ /* After the next statement, TempLine should contain two separate data elements: the date and the price */ TempLine = split (TransactionsFromFile[TransactionCounter], ","); for (DateCounter = 0; DateCounter < numDates; DateCounter++) { println("dc=" + DateCounter + " | " + DatesFromFile[DateCounter] + " | " + TempLine[0] + " | tc=" + TransactionCounter + " | templine.length=" + TempLine.length); if (!DatesFromFile[DateCounter].equals(TempLine[0])) // TempLine[0] contains the transaction date { OutputFile.println(DatesFromFile[DateCounter] + ",0"); } else { OutputFile.println(TransactionsFromFile[TransactionCounter]); TransactionCounter++; if (TransactionCounter < TransactionsFromFile.length) TempLine = split (TransactionsFromFile[TransactionCounter], ","); } } OutputFile.flush(); OutputFile.close(); exit();