Last active
September 21, 2024 03:53
-
-
Save JavierSolis/025ce7553529743fa2e75f944bb1f874 to your computer and use it in GitHub Desktop.
Práctica: Conceptos básicos de Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //solution completed: | |
| //https://developer.android.com/codelabs/basic-android-kotlin-compose-kotlin-fundamentals-practice-problems?hl=es-419&continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-2-pathway-1%3Fhl%3Des-419%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-kotlin-fundamentals-practice-problems#8 | |
| fun main(){ | |
| notifications() | |
| tycketCine() | |
| catalogSong() | |
| } | |
| //5. Catálogo de canciones | |
| class Song(val title:String,val artist:String,val year:String,val count:Int){ | |
| fun isPopular(){ | |
| println("$title, interpretada por $artist, se lanzo en $year") | |
| if(count<1000){ | |
| print(" es poco popular\n") | |
| } | |
| else{ | |
| print(" es popular\n") | |
| } | |
| } | |
| } | |
| fun catalogSong(){ | |
| Song("Jojo","Javier","1900",1000).isPopular() | |
| Song("Jao","Solis","1500",100).isPopular() | |
| } | |
| //3. Precio de la entrada de cine | |
| //[start] | |
| fun tycketCine() { | |
| val child = 5 | |
| val adult = 28 | |
| val senior = 87 | |
| val isMonday = true | |
| println("The movie ticket price for a person aged $child is \$${ticketPrice(child, isMonday)}.") | |
| println("The movie ticket price for a person aged $adult is \$${ticketPrice(adult, isMonday)}.") | |
| println("The movie ticket price for a person aged $senior is \$${ticketPrice(senior, isMonday)}.") | |
| } | |
| fun ticketPrice(age: Int, isMonday: Boolean): Int { | |
| return when{ | |
| age<12->15 | |
| age>13 && age<60 && !isMonday->30 | |
| age>13 && age<60 && isMonday->25 | |
| age>=61 -> 20 | |
| else -> -1 | |
| } | |
| } | |
| //[end] | |
| //2. Notificaciones móviles | |
| //[start] | |
| fun notifications() { | |
| val morningNotification = 51 | |
| val eveningNotification = 135 | |
| printNotificationSummary(morningNotification) | |
| printNotificationSummary(eveningNotification) | |
| } | |
| fun printNotificationSummary(numberOfMessages: Int) { | |
| if(numberOfMessages<100){ | |
| println("You have $numberOfMessages notifications.") | |
| } | |
| else{ | |
| println("Your phone is blowing up! You have 99+ notifications.") | |
| } | |
| } | |
| //[End] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment