├── .github └── FUNDING.yml ├── README.md ├── circlearea.kt ├── controlFlow.kt ├── coroutines.kt ├── inheritance.kt ├── oddeven.kt └── oop.kt /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: kokonior 4 | patreon: kokonior 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kotlin-Projects 2 | #Hacktoberfest 3 | -------------------------------------------------------------------------------- /circlearea.kt: -------------------------------------------------------------------------------- 1 | import java.util.* 2 | 3 | fun main() { 4 | val read = Scanner(System.`in`) 5 | cuma sekali buat 6 | val phi = 3.14 7 | 8 | print("Input circle radius: ") 9 | var jari:Float = read.nextFloat() 10 | tapi 11 | 12 | var luas = phi * jari * jari 13 | var keliling = 2 * phi * jari 14 | 15 | println("circumference: $keliling") 16 | println("area of circle : $luas") 17 | -------------------------------------------------------------------------------- /controlFlow.kt: -------------------------------------------------------------------------------- 1 | /* basic control flow with kotlin */ 2 | 3 | fun main() { 4 | val listNumber = 1.rangeTo(100) 5 | 6 | for (number in listNumber) { 7 | 8 | if (number %2 == 0) continue 9 | 10 | 11 | if (number >= 20) break 12 | 13 | 14 | val result = number * 10 / 2 15 | println("range result is $result") 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /coroutines.kt: -------------------------------------------------------------------------------- 1 | 2 | // kotlin coroutines 3 | import kotlinx.coroutines.* 4 | 5 | suspend fun sum(valueA: Int, valueB: Int, valueC: Int): Int { 6 | delay(3000L) 7 | return valueA + valueB * valueC 8 | } 9 | 10 | suspend fun multiple(valueA: Int, valueB: Int, valueC: Int): Int { 11 | delay(2000L) 12 | return valueA * valueB - valueC 13 | } 14 | 15 | fun main() = runBlocking { 16 | 17 | println("Counting...") 18 | 19 | val resultSum = async { sum(30, 20, 20) } 20 | val resultMultiple = async { multiple(40, 20, 40) } 21 | 22 | println("Result sum: ${resultSum.await()}") 23 | println("Result multiple: ${resultMultiple.await()}") 24 | 25 | } 26 | -------------------------------------------------------------------------------- /inheritance.kt: -------------------------------------------------------------------------------- 1 | fun main() { 2 | val cat = Cat() 3 | cat.eat() 4 | } 5 | 6 | open class Animal{ 7 | fun walk(){ 8 | println("${javaClass.simpleName} walk!") 9 | } 10 | } 11 | 12 | open class Carnivore: Animal(){ 13 | fun eat(){ 14 | println("${javaClass.simpleName} eat!") 15 | } 16 | } 17 | 18 | class Cat: Carnivore() -------------------------------------------------------------------------------- /oddeven.kt: -------------------------------------------------------------------------------- 1 | fun main(){ 2 | var bilangan: Int 3 | 4 | println("Odd Even Validator") 5 | print("Input Number: ") 6 | bilangan = readLine()!!.toInt() 7 | 8 | if(bilangan % 2 == 0) 9 | println("The number is Even") 10 | else 11 | println("The number is Odd") 12 | } 13 | -------------------------------------------------------------------------------- /oop.kt: -------------------------------------------------------------------------------- 1 | // oop with kotlin 2 | class Lion(private val name: String) { 3 | 4 | var sleep: Boolean = false 5 | 6 | get() { 7 | println("Fungsi getter dipanggil") 8 | return field 9 | } 10 | set(value) { 11 | println("Fungsi setter dipanggil") 12 | field = value 13 | } 14 | 15 | fun toSleep() { 16 | if (sleep) { 17 | println("$name, sleep!") 18 | } else { 19 | println("$name, let's play!") 20 | } 21 | } 22 | } 23 | 24 | fun main() { 25 | 26 | val simba = Lion("Simba") 27 | 28 | simba.toSleep() 29 | simba.sleep = true 30 | simba.toSleep() 31 | } 32 | --------------------------------------------------------------------------------