Initial Commit
This commit is contained in:
76
src/ams.kt
Normal file
76
src/ams.kt
Normal file
@@ -0,0 +1,76 @@
|
||||
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())]
|
||||
}
|
||||
6
src/dice.kt
Normal file
6
src/dice.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
import java.util.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val roll12 = { Random().nextInt(12) + 1 }
|
||||
val rollDie: (Int) -> Int = { sides -> if (sides == 0) 0 else Random().nextInt(sides) + 1 }
|
||||
}
|
||||
31
src/fortune.kt
Normal file
31
src/fortune.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
fun main(args: Array<String>) {
|
||||
val birthday = getBirthday()
|
||||
val fortune = getFortune(birthday)
|
||||
println("Your fortune is: $fortune")
|
||||
}
|
||||
|
||||
fun getBirthday(): Int {
|
||||
print("Enter your birthday:")
|
||||
return readLine()?.toIntOrNull() ?: 1
|
||||
}
|
||||
|
||||
fun getFortune(birthday: Int): String {
|
||||
val fortunes = listOf<String>(
|
||||
"You will have a great day!",
|
||||
"Things will go well for you today.",
|
||||
"Enjoy a wonderful day of success.",
|
||||
"Be humble and all will turn out well.",
|
||||
"Today is a good day for exercising restraint.",
|
||||
"Take it easy and enjoy life!",
|
||||
"Treasure your friends because they are your greatest fortune."
|
||||
)
|
||||
val index = when(birthday) {
|
||||
in 1..5 -> 4
|
||||
6, 22 -> 5
|
||||
else -> birthday.rem(fortunes.size)
|
||||
}
|
||||
return fortunes[index]
|
||||
}
|
||||
|
||||
|
||||
|
||||
23
src/whatToDoToday.kt
Normal file
23
src/whatToDoToday.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
fun main(args: Array<String>) {
|
||||
println(whatShouldIDoToday("happy"))
|
||||
}
|
||||
|
||||
fun whatShouldIDoToday(
|
||||
mood: String,
|
||||
weather: String = "sunny",
|
||||
temp: Int = 24
|
||||
): String {
|
||||
return when {
|
||||
isHappyMood(mood) && isSunnyWeather(weather) -> "go for a walk"
|
||||
isSadMood(mood) && isRainyWeather(weather) && isColdTemp(temp) -> "stay in bed"
|
||||
isWarmTemp(temp) -> "go swimming"
|
||||
else -> "stay home and read"
|
||||
}
|
||||
}
|
||||
|
||||
fun isHappyMood(mood: String) = mood == "happy"
|
||||
fun isSadMood(mood: String) = mood == "sad"
|
||||
fun isSunnyWeather(weather: String) = weather == "sunny"
|
||||
fun isRainyWeather(weather: String) = weather == "rainy"
|
||||
fun isColdTemp(temp: Int) = temp <= 0
|
||||
fun isWarmTemp(temp: Int) = temp >= 23
|
||||
Reference in New Issue
Block a user