Exemplo n.º 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:");
 }
 public static void testLowestHumidityInFile() {
   FileResource fr = new FileResource();
   CSVParser csv = fr.getCSVParser();
   CSVRecord record = lowestHumidityInFile(csv);
   System.out.println(
       "Lowest Humidity was " + record.get("Humidity") + " at " + record.get("DateUTC"));
 }
Exemplo n.º 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);
   }
 }
 public static void testAverageTemperatureWithHighHumidityInFile(int value) {
   FileResource fr = new FileResource();
   CSVParser parser = fr.getCSVParser();
   Double average = averageTemperatureWithHighHumidityInFile(parser, value);
   if (average == null) {
     System.out.println("No temperatures with that humidity");
   } else {
     System.out.println("Average Temp when high Humidity is " + average);
   }
 }
 public static CSVRecord lowestHumidityInManyFiles() {
   CSVRecord lowestSoFar = null;
   DirectoryResource dir = new DirectoryResource();
   for (File file : dir.selectedFiles()) {
     FileResource fr = new FileResource(file);
     CSVParser csv = fr.getCSVParser();
     CSVRecord lowestInFile = lowestHumidityInFile(csv);
     lowestSoFar = getLowestOfTwo(lowestInFile, lowestSoFar);
   }
   return lowestSoFar;
 }
Exemplo n.º 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;
 }
 /**
  * Takes selected files and returns name of file with lowest temp
  *
  * @return name of file with lowest temperature
  */
 public static String fileWithColdestTemperature() {
   DirectoryResource dir = new DirectoryResource();
   CSVRecord lowestSoFar = null;
   File lowestFile = null;
   for (File fr : dir.selectedFiles()) {
     FileResource frR = new FileResource(fr);
     CSVParser csv = frR.getCSVParser();
     CSVRecord record = coldestHourInFile(csv);
     if (coldestOfTwo(record, lowestSoFar)) {
       lowestFile = fr;
     }
   }
   return lowestFile.getAbsolutePath();
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
0
  /*	public boolean doesNameRepeats(FileResource fr, CSVRecord reader) {
  		int counter = 0;
  		int birthsNumbers = Integer.parseInt(reader.get(2));
  		for (CSVRecord secondReader : fr.getCSVParser(false)) {
  			if(secondReader.get(0).equals(name));
  			counter++;
  		}
  		if (counter > 1)
  			return true;
  		else
  			return false;
  	}
  */
  public void totalBirths(FileResource fr) {

    int totalBirths = 0;
    int totalGirls = 0;
    int totalBoys = 0;

    int uniqueBirths = 0;
    int uniqueGirls = 0;
    int uniqueBoys = 0;

    String uniqueName = "";

    for (CSVRecord reader : fr.getCSVParser(false)) {
      int brojRodjenih = Integer.parseInt(reader.get(2));
      totalBirths += brojRodjenih;

      // ---1--- ako se ime ne ponavlja, pokrecemo counter, ako ne, preskacemo counter
      uniqueBirths =
          uniqueBirths + (Integer.parseInt(reader.get(2)) - (Integer.parseInt(reader.get(2)) - 1));

      if (reader.get(1).equals("F")) totalGirls += brojRodjenih;
      else totalBoys += brojRodjenih;
    }
    System.out.println("Potpuni broj rodjenih: " + totalBirths);
    System.out.println("Broj zenske djece: " + totalGirls);
    System.out.println("Broj muske djece: " + totalBoys);
    System.out.println("Broj svih imena: " + uniqueBirths);
  }
Exemplo n.º 10
0
  public void printNames() {
    FileResource fr = new FileResource();

    for (CSVRecord record : fr.getCSVParser(false)) {
      int numero = Integer.parseInt(record.get(2));
      if (numero <= 100) {
        System.out.println(
            "ime bebe: "
                + record.get(0)
                + "    \t"
                + "spol: "
                + record.get(1)
                + "    \t"
                + "broj istih imena u godini: "
                + record.get(2));
      }
    }
  }
 public static void testFileWithColdestTemp() {
   String lowestFile = fileWithColdestTemperature();
   FileResource lowestFile2 = new FileResource(lowestFile);
   String lowestFile1 = lowestFile.substring(lowestFile.lastIndexOf("\\") + 1);
   CSVParser csv = lowestFile2.getCSVParser();
   CSVRecord record = coldestHourInFile(csv);
   System.out.println("Coldest day was in file " + lowestFile1);
   System.out.println("Coldest temperature on that day was " + record.get("TemperatureF"));
   System.out.println("All the temperatures on that day are:");
   csv = lowestFile2.getCSVParser();
   for (CSVRecord row : csv) {
     System.out.println(
         lowestFile1.substring(8, lowestFile1.length() - 4)
             + " "
             + row.get("TimeEST")
             + " "
             + row.get("TemperatureF"));
   }
 }
Exemplo n.º 12
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"));
 }
Exemplo n.º 13
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);
 }
 public static void testColdestHourInFile() {
   FileResource fr = new FileResource();
   CSVParser csv = fr.getCSVParser();
   CSVRecord lowest = coldestHourInFile(csv);
   System.out.println(lowest.get("DateUTC") + " " + lowest.get("TemperatureF"));
 }