Weather comparison

Report a typo

Consider a program that takes three integer inputs representing the temperatures in Dubai, Moscow, and Hanoi, and then prints the name of the coldest city based on the following conditions:

  • If a temperature is less than -92°C or greater than 57°C, the city's average temperature is used as the default:

    • Dubai: 30°C

    • Moscow: 5°C

    • Hanoi: 20°C

  • If two or more cities share the coldest temperature, the program prints "neither".

Your task is to complete the implementation of the City class and the comparison logic in the printColdestCity function of this program.

Sample Input 1:

20
100
35

Sample Output 1:

Moscow
Write a program in Kotlin
// Do not change the constructor
class City(val name: String) {
// Do not change the property name "temperature"
var temperature: Int
}

fun printColdestCity(dubai: City, moscow: City, hanoi: City) {
// Implement the comparison logic here

println(/* Name of the coldest city or "neither" */)
}
___

Create a free account to access the full topic