コード例 #1
1
 public static void fileWithColdestTemperature() {
   String fileName = null;
   CSVRecord lowestSoFar = null;
   double lowestTemp = 99999;
   DirectoryResource dr = new DirectoryResource();
   for (File f : dr.selectedFiles()) {
     FileResource fr = new FileResource(f);
     CSVRecord currentRow = coldestHourInFile(fr.getCSVParser());
     double currentTemp = Double.parseDouble(currentRow.get("TemperatureF"));
     if (currentTemp < lowestTemp) {
       lowestTemp = currentTemp;
       lowestSoFar = currentRow;
       fileName = f.getName();
     }
     /*
     if (lowestSoFar == null) {
     	lowestSoFar = currentRow;
     	fileName = f.getName();
     	selectedFr = fr;
     } else {
     	lowestSoFar = getLowestOfTwo(currentRow, lowestSoFar);
     	fileName = f.getName();
     	selectedFr = fr;
     }
     */
   }
   System.out.println("Coldest day was in file " + fileName);
   System.out.println("Coldest temperature on that day was " + lowestSoFar.get("TemperatureF"));
   System.out.println("All the Temperatures on the coldest day were:");
 }
コード例 #2
0
  public void quiz1_q1() {
    FileResource fr = new FileResource("../secretmessage1.txt");
    String encrypted = fr.asString();

    int[] key = new int[4];
    key = tryKeyLength(encrypted, 4, 'e');
    for (int i = 0; i < 4; i++) {
      System.out.println(key[i]);
    }
  }
コード例 #3
0
 public static void testAverageTemperatureWithHighHumidityInFile() {
   FileResource fr = new FileResource();
   CSVParser parser = fr.getCSVParser();
   double avgTem = averageTemperatureWithHighHumidityInFile(parser, 80);
   if (avgTem == -9999) {
     System.out.println("No temperatures with that humidity");
   } else {
     System.out.println("Average Temp when high Humidity is " + avgTem);
   }
 }
コード例 #4
0
  public void testTryKeyLength() {

    FileResource fr = new FileResource("athens_keyflute.txt");
    String encrypted = fr.asString();

    int[] key = new int[5];
    key = tryKeyLength(encrypted, 5, 'e');
    for (int i = 0; i < 5; i++) {
      System.out.println(key[i]);
    }
  }
コード例 #5
0
  public void breakVigenere() {

    // read in the encrypted message
    FileResource fr = new FileResource();
    String encrypted = fr.asString();

    // read in the dictionary of valid words
    FileResource dictRes = new FileResource("dictionaries/English");
    HashSet<String> dict = readDictionary(dictRes);

    String decrypted = breakForLanguage(encrypted, dict);
    System.out.println(decrypted);
  }
コード例 #6
0
 public static CSVRecord hottestInManyDays() {
   CSVRecord largestSoFar = null;
   DirectoryResource dr = new DirectoryResource();
   for (File f : dr.selectedFiles()) {
     FileResource fr = new FileResource(f);
     CSVRecord currentRow = hottestHourInFile(fr.getCSVParser());
     if (largestSoFar == null) {
       largestSoFar = currentRow;
     } else {
       largestSoFar = getLargestOfTwo(currentRow, largestSoFar);
     }
   }
   return largestSoFar;
 }
コード例 #7
0
 public static CSVRecord lowestHumidityInManyFiles() {
   CSVRecord lowestRecordSoFar = null;
   double lowestHumiditySoFar = 101;
   DirectoryResource dr = new DirectoryResource();
   for (File f : dr.selectedFiles()) {
     FileResource fr = new FileResource(f);
     CSVParser parser = fr.getCSVParser();
     CSVRecord record = lowestHumidityInFile(parser);
     double currentHumidity = Double.parseDouble(record.get("Humidity"));
     if (currentHumidity < lowestHumiditySoFar) {
       lowestHumiditySoFar = currentHumidity;
       lowestRecordSoFar = record;
     }
   }
   return lowestRecordSoFar;
 }
コード例 #8
0
  public void testBreakForAllLanguages() {

    // read in the encrypted message
    FileResource fr2 = new FileResource("athens_keyflute.txt");
    String encrypted = fr2.asString();

    HashMap<String, HashSet<String>> myMap = new HashMap<String, HashSet<String>>();

    FileResource fr = new FileResource("dictionaries/English");
    HashSet<String> dict = readDictionary(fr);

    myMap.put("English", dict);

    FileResource fr1 = new FileResource("dictionaries/Spanish");
    HashSet<String> dict1 = readDictionary(fr1);

    myMap.put("Spanish", dict1);

    breakForAllLanguages(encrypted, myMap);
  }
コード例 #9
0
  /*
   *  method to return a HashSet of words lower-cased and read from the file
   *  passed in as a parameter
   */
  public HashSet<String> readDictionary(FileResource fr) {

    // create a HashSet which you will be returning
    HashSet<String> dict = new HashSet<String>();

    for (String line : fr.lines()) {

      // convert to lowercase and add to the dictionary
      line = line.toLowerCase();
      dict.add(line);
    }
    return dict;
  }
コード例 #10
0
 public static void testColdestHourInFile() {
   FileResource fr = new FileResource();
   CSVParser parser = fr.getCSVParser();
   CSVRecord coldest = coldestHourInFile(parser);
   System.out.println(coldest.get("TemperatureF") + " at " + coldest.get("TimeEST"));
 }
コード例 #11
0
 public static void testAverageTemperatureInFile() {
   FileResource fr = new FileResource();
   CSVParser parser = fr.getCSVParser();
   double averageTemperature = averageTemperatureInFile(parser);
   System.out.println("Average temperature in file is " + averageTemperature);
 }
コード例 #12
0
 public static void testLowestHumidityInFile() {
   FileResource fr = new FileResource();
   CSVParser parser = fr.getCSVParser();
   CSVRecord csv = lowestHumidityInFile(parser);
   System.out.println("Lowest Humidity was " + csv.get("Humidity") + " at " + csv.get("DateUTC"));
 }