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
fun main() { | |
val morningNotification = 51 | |
val eveningNotification = 135 | |
printNotificationSummary(morningNotification) | |
printNotificationSummary(eveningNotification) | |
} | |
fun printNotificationSummary(numberOfMessages: Int) { | |
if (numberOfMessages < 100) { |
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
fun main() { | |
val winningBid = Bid(5000, "Private Collector") | |
println("Item A is sold at ${auctionPrice(winningBid, 2000)}.") | |
println("Item B is sold at ${auctionPrice(null, 3000)}.") | |
} | |
class Bid(val amount: Int, val bidder: String) | |
fun auctionPrice(bid: Bid?, minimumPrice: Int): Int { |
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
class Person( | |
val name: String, | |
val age: Int, | |
val hobby: String?, | |
val referrer: Person? | |
) { | |
fun showProfile() { | |
println("Name: $name") | |
println("Age: $age") |
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
class Song( | |
val title: String, | |
val artist: String, | |
val year: Int, | |
val playCount: Int | |
) { | |
val isPopular: Boolean | |
get() = playCount >= 1000 |
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
fun main() { | |
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 { |