76 lines
1.8 KiB
Kotlin
76 lines
1.8 KiB
Kotlin
import java.util.*
|
|
|
|
fun main(args: Array<String>) {
|
|
feedTheFish()
|
|
}
|
|
|
|
fun shouldChangeWater(
|
|
day: String,
|
|
temp: Int = 22,
|
|
dirty: Int = 22
|
|
): Boolean {
|
|
return when {
|
|
isTooHot(temp) -> true
|
|
isDirty(dirty) -> true
|
|
isSunday(day) -> true
|
|
else -> false
|
|
}
|
|
}
|
|
|
|
fun isTooHot(temp: Int) = temp > 30
|
|
fun isDirty(dirty: Int) = dirty > 30
|
|
fun isSunday(day: String) = day == "Sunday"
|
|
|
|
fun dayOfWeek() {
|
|
println("What day is it today?")
|
|
var day: String? = null
|
|
day = when(Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) {
|
|
1 -> "Sunday"
|
|
2 -> "Monday"
|
|
3 -> "Tuesday"
|
|
4 -> "Wednesday"
|
|
5 -> "Thursday"
|
|
6 -> "Friday"
|
|
7 -> "Saturday"
|
|
else -> "wut?"
|
|
}
|
|
println("Today is: $day")
|
|
}
|
|
|
|
fun feedTheFish() {
|
|
val day = randomDay()
|
|
val food = fishFood(day)
|
|
print("Today is $day and the fish eat $food")
|
|
if (shouldChangeWater(day)) {
|
|
println("Change the water today")
|
|
}
|
|
}
|
|
|
|
fun fitMoreFish(
|
|
tankSize: Double,
|
|
currentFish: List<Int>,
|
|
fishSize: Int = 2,
|
|
hasDecorations: Boolean = true
|
|
): Boolean {
|
|
val tankCap = tankSize.times(if(hasDecorations) 0.8 else 1.0)
|
|
val currentTotalSize = if(currentFish.isNotEmpty()) currentFish.sum() else 0
|
|
return tankCap.minus(currentTotalSize) >= fishSize
|
|
}
|
|
|
|
fun fishFood(day: String): String {
|
|
return when(day) {
|
|
"Monday" -> "flakes"
|
|
"Tuesday" -> "pellets"
|
|
"Wednesday" -> "redworms"
|
|
"Thursday" -> "granules"
|
|
"Friday" -> "mosquitoes"
|
|
"Saturday" -> "lettuce"
|
|
"Sunday" -> "plankton"
|
|
else -> "fasting"
|
|
}
|
|
}
|
|
|
|
fun randomDay() : String {
|
|
val week = listOf<String>("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
|
|
return week[Random().nextInt(week.count())]
|
|
} |