Created
November 7, 2020 20:55
-
-
Save skywall/d2fe655907a8ed387294f403013e70bf to your computer and use it in GitHub Desktop.
TicketMachineParts
This file contains 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
enum class TicketType(val coins: Int) { | |
ADULT(2), | |
CHILD(1), | |
} | |
class Printer( | |
private val display: Display, | |
) { | |
fun printTicket(selectedTicketType: TicketType) { | |
display.show("Ticket printed: ${selectedTicketType.name}") | |
} | |
} | |
class Display { | |
fun show(text: String) { println("> $text") } | |
} | |
class CoinCounter { | |
private var insertedCoins = 0 | |
fun insertCoin() { insertedCoins += 1 } | |
fun getMissingCoins(selectedTicketType: TicketType): Int { | |
return selectedTicketType.coins - insertedCoins | |
} | |
fun getInsertedCoins() = insertedCoins | |
fun reset() { insertedCoins = 0 } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment