/**
 * This function takes in the population and area size of a village and calculates the density of the village.
 *
 * @param population The population of the village.
 * @param areaSize The area size of the village in square kilometers.
 * @return The village density in individuals per square kilometer.
 */
fun calculateVillageDensity(population: Int, areaSize: Float): Float {

    var density = 0.0f

    // Calculate the village density
    var currentPopulation = population
    while (currentPopulation > 0) {
        // Prompt the user to enter the name of a geographical feature
        print("Enter the name of a geographical feature (e.g. lake, river, mountain): ")
        val featureName = readLine()

        // Create an empty set to store the features
        val featuresSet = mutableSetOf<String>()

        // Prompt the user to enter the number of features for the given name
        print("How many ${featureName}s does the village have? ")
        val numFeatures = readLine()?.toIntOrNull() ?: 0

        // Nested loop to collect the features
        for (i in 1..numFeatures) {
            print("Enter the name of ${featureName} $i: ")
            val feature = readLine()
            feature?.let { featuresSet.add(it) }
        }

        println("The village has $numFeatures $featureName(s).")
        currentPopulation--
    }

    return density
}
/**
 * This function takes in the population and area size of a village and calculates the density of the village.
 *
 * @param population The population of the village.
 * @param areaSize The area size of the village in square kilometers.
 * @return The village density in individuals per square kilometer.
 */
fun calculateVillageDensity(population: Int, areaSize: Float): Float {
/**
 * This function takes in the population and area size of a village and calculates the density of the village.
 *
 * @param population The population of the village.
 * @param areaSize The area size of the village in square kilometers.
 * @return The village density in individuals per square kilometer.
 */
fun calculateVillageDensity(population: Int, areaSize: Float): Float {

    var density = 0.0f

    // Calculate the village density
    var currentPopulation = population
    while (currentPopulation > 0) {
        // Prompt the user to enter the name of a geographical feature
        print("Enter the name of a geographical feature (e.g. lake, river, mountain): ")
        val featureName = readLine()

        // Create an empty set to store the features
        val featuresSet = mutableSetOf<String>()

        // Prompt the user to enter the number of features for the given name
        print("How many ${featureName}s does the village have? ")
        val numFeatures = readLine()?.toIntOrNull() ?: 0

        // Nested loop to collect the features
        for (i in 1..numFeatures) {
            print("Enter the name of ${featureName} $i: ")
            val feature = readLine()
            feature?.let { featuresSet.add(it) }
        }

        println("The village has $numFeatures $featureName(s).")
        currentPopulation--
    }

    return density
}