weather

import scala.io.Source

object WeatherStats {
  def main(args: Array[String]): Unit = {
    val filename = "sample_weather.txt"

    try {
      // Read and process the file
      val dataLines = Source.fromFile(filename).getLines().drop(1)

      var tempSum, dewSum, windSum, count = 0.0

      dataLines.foreach { line =>
        if (fields.length == 4) {
          tempSum += fields(1).toDouble
          dewSum += fields(2).toDouble
          windSum += fields(3).toDouble
          count += 1
        }
      }

      // Calculate and display averages
      if (count > 0) {
        println(f"Average Temperature: ${tempSum / count}%.2f ยฐC")
        println(f"Average Dew Point: ${dewSum / count}%.2f ยฐC")
        println(f"Average Wind Speed: ${windSum / count}%.2f km/h")
      } else {
        println("No valid data found.")
      }

    } catch {
      case ex: Exception => println(s"Error: ${ex.getMessage}")
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

  • K2-18b: The second earth?!

    Alien Burps, Cosmic Oceans & A Planet That Might Be a Giant Jacuzzi Imagine a planet 124 light-years away that might be bubbling with lifeโ€”minus the WiFi and coffee shops. Enter K2-18b, a mysterious exoplanet hanging out in the constellation Leo, now famous…

  • Can we use Quantum Computing for Searching the Alien Life?

    Humans are obsessed with finding extraterrestrial life. From sci-fi movies to conspiracy theories about Area 51, weโ€™ve spent decades wondering if weโ€™re alone in the universe. But despite our best efforts, ET seems to be playing an epic game of hide-and-seek. Enter quantum…

  • Planetary Alignment in January 2025: why this celestial tea is piping hot ?

    The night sky is serving looks this January, and weโ€™re all invited to the ultimate glow-up party hosted by our solar system. Thatโ€™s right, a rare planetary alignment is happening, and itโ€™s giving main character energy. Letโ€™s talk about why this celestial tea…

  • Meet the Baby Planets: PDS 70b and PDS 70c

    PDS 70: A Star Forming Planets Before Our Eyes Imagine witnessing the birth of an entire planet. Thatโ€™s exactly what astronomers are observing in the PDS 70 system, a cosmic nursery located 370 light-years away in the constellation Centaurus. This young star system…