Answered step by step
Verified Expert Solution
Question
1 Approved Answer
here is my code so far but I cant get it to run properly because I keep getting an error code saying 75:14 Kotlin: Expecting
here is my code so far but I cant get it to run properly because I keep getting an error code saying 75:14 Kotlin: Expecting ')' import java.io.File class Weather(val date: String, val precipitation: Float, val snowfall: Float, val snowDepth: Float, val maxTemperature: Float, val minTemperature: Float, val avgTemperature: Float, val heatingDegreeDays: Float, val coolingDegreeDays: Float, val sunrise: String, val sunset: String, val lengthOfDay: String) fun readData(): Map{ val weatherDB = mutableMapOf () val lines = File("weather.db").readLines().drop(1) for (line in lines) { val row = line.split(",") val date = row[0] val precipitation = row[1].toFloat() val snowfall = row[2].toFloat() val snowDepth = row[3].toFloat() val maxTemperature = row[4].toFloat() val minTemperature = row[5].toFloat() val avgTemperature = row[6].toFloat() val heatingDegreeDays = row[7].toFloat() val coolingDegreeDays = row[8].toFloat() val sunrise = row[9] val sunset = row[10] val lengthOfDay = row[11] val key = getKey(date) weatherDB[key] = Weather(date, precipitation, snowfall, snowDepth, maxTemperature, minTemperature, avgTemperature, heatingDegreeDays, coolingDegreeDays, sunrise, sunset, lengthOfDay) } return weatherDB } fun getKey(date: String): String { val (month, day) = date.split("/") return "${month.padStart(2, '0')}/${day.padStart(2, '0')}" } fun printHeader() { println("%-10s%-15s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-15s".format( "Date", "Precipitation", "Snowfall", "Snow Depth", "Max Temp.", "Min Temp.", "Avg Temp.", "HDD", "CDD", "Sunrise", "Sunset", "Length of Day")) } fun printAllRecords(weatherDB: Map ) { printHeader() for ((_, weather) in weatherDB) { println("%-10s%-15.2f%-10.2f%-10.2f%-10.2f%-10.2f%-10.2f%-10.2f%-10.2f%-10s%-10s%-15s".format( weather.date, weather.precipitation, weather.snowfall, weather.snowDepth, weather.maxTemperature, weather.minTemperature, weather.avgTemperature, weather.heatingDegreeDays, weather.coolingDegreeDays, weather.sunrise, weather.sunset, weather.lengthOfDay)) } } fun printRecordsFromSingleMonth(weatherDB: Map ) { printHeader() print("Enter month (MM): ") val month = readLine()!!.padStart(2, '0') for ((key, weather) in weatherDB) { if (key.startsWith(month)) { println(message = "%-10s%-15.2f%-10.2f%-10.2f%-10.2f%-10.2f%-10.2f%-10.2f%-10.2f%-10s%-10s%-15s".format( weather.date, weather.precipitation, weather.snowfall, weather.snowDepth, weather.maxTemperature, weather.minTemperature, weather.avgTemperature, weather ) }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started