commit 3585879e64c7d1721dafd28865138238db939392 Author: Andrew Kemp Date: Tue Mar 3 08:18:35 2020 -0500 Initial Commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..1bec35e --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..16533ee --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..1a7265d --- /dev/null +++ b/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..5e2308c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HelloKotlin.iml b/HelloKotlin.iml new file mode 100644 index 0000000..245d342 --- /dev/null +++ b/HelloKotlin.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/HelloKotlin/AmsKt.class b/out/production/HelloKotlin/AmsKt.class new file mode 100644 index 0000000..5971c78 Binary files /dev/null and b/out/production/HelloKotlin/AmsKt.class differ diff --git a/out/production/HelloKotlin/FortuneKt.class b/out/production/HelloKotlin/FortuneKt.class new file mode 100644 index 0000000..c4d1987 Binary files /dev/null and b/out/production/HelloKotlin/FortuneKt.class differ diff --git a/out/production/HelloKotlin/META-INF/HelloKotlin.kotlin_module b/out/production/HelloKotlin/META-INF/HelloKotlin.kotlin_module new file mode 100644 index 0000000..826e881 Binary files /dev/null and b/out/production/HelloKotlin/META-INF/HelloKotlin.kotlin_module differ diff --git a/out/production/HelloKotlin/WhatToDoTodayKt.class b/out/production/HelloKotlin/WhatToDoTodayKt.class new file mode 100644 index 0000000..f8177ba Binary files /dev/null and b/out/production/HelloKotlin/WhatToDoTodayKt.class differ diff --git a/src/ams.kt b/src/ams.kt new file mode 100644 index 0000000..8dc35ed --- /dev/null +++ b/src/ams.kt @@ -0,0 +1,76 @@ +import java.util.* + +fun main(args: Array) { + 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, + 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("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") + return week[Random().nextInt(week.count())] +} \ No newline at end of file diff --git a/src/dice.kt b/src/dice.kt new file mode 100644 index 0000000..0efad84 --- /dev/null +++ b/src/dice.kt @@ -0,0 +1,6 @@ +import java.util.* + +fun main(args: Array) { + val roll12 = { Random().nextInt(12) + 1 } + val rollDie: (Int) -> Int = { sides -> if (sides == 0) 0 else Random().nextInt(sides) + 1 } +} \ No newline at end of file diff --git a/src/fortune.kt b/src/fortune.kt new file mode 100644 index 0000000..707226e --- /dev/null +++ b/src/fortune.kt @@ -0,0 +1,31 @@ +fun main(args: Array) { + 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( + "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] +} + + + diff --git a/src/whatToDoToday.kt b/src/whatToDoToday.kt new file mode 100644 index 0000000..6dd0bae --- /dev/null +++ b/src/whatToDoToday.kt @@ -0,0 +1,23 @@ +fun main(args: Array) { + 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 \ No newline at end of file