Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/second edit function 2 #10

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dataSource.CsvDataSource
import dataSource.utils.CsvParser
import interactor.CostOfLivingDataSource
import interactor.GetCityHasCheapestInternetConnectionInteractor
import interactor.GetCitiesNamesForLowestCostByAverageFruitAndVegetablesInteractor
import interactor.GetHighestSalaryAverageCititesNamesInteractor

fun main() {
Expand All @@ -12,9 +12,11 @@ fun main() {
println(getHighestSalaryAverageCities.execute(limit = 10))
printSeparationLine()

val getCityHasCheapestInternetConnectionInteractor = GetCityHasCheapestInternetConnectionInteractor(dataSource)
println(getCityHasCheapestInternetConnectionInteractor.execute())
// val getCityHasCheapestInternetConnectionInteractor = GetCityHasCheapestInternetConnectionInteractor(dataSource)
// println(getCityHasCheapestInternetConnectionInteractor.execute())

val getCitiesNamesForLowestCostByAverageFruitAndVegetablesInteractor = GetCitiesNamesForLowestCostByAverageFruitAndVegetablesInteractor(dataSource)
println(getCitiesNamesForLowestCostByAverageFruitAndVegetablesInteractor.execute(10))
}
private fun printSeparationLine(){
print("\n_______________________________\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package interactor

import model.CityEntity

class GetCitiesNamesForLowestCostByAverageFruitAndVegetables(
class GetCitiesNamesForLowestCostByAverageFruitAndVegetablesInteractor(
private val dataSource: CostOfLivingDataSource
) {

Expand All @@ -21,15 +21,19 @@ class GetCitiesNamesForLowestCostByAverageFruitAndVegetables(
}

fun calculateAverageFruitAndVegetables(cityEntity: CityEntity): Float{
val kilos = cityEntity.fruitAndVegetablesPrices
val sumList = listOf(kilos.apples1kg, kilos.banana1kg,
kilos.oranges1kg, kilos.tomato1kg,
kilos.potato1kg, kilos.onion1kg,
kilos.lettuceOneHead)
val kilos = cityEntity.fruitAndVegetablesPrices!!

val total = kilos.run {
apples1kg!! + banana1kg!! + oranges1kg!! + tomato1kg!! + potato1kg!! + onion1kg!! + lettuceOneHead!!
}
return total / NUMBER_OF_VARIABLES
}

fun AverageFruitAndVegetablesVsAverageSalaries(cityEntity: CityEntity): Float {
return calculateAverageFruitAndVegetables(cityEntity) / cityEntity.averageMonthlyNetSalaryAfterTax!!
}

companion object {
const val NUMBER_OF_VARIABLES = 7
}
}
Loading