Skip to content

Instantly share code, notes, and snippets.

@skywall
Created November 7, 2020 20:55
Show Gist options
  • Save skywall/d2fe655907a8ed387294f403013e70bf to your computer and use it in GitHub Desktop.
Save skywall/d2fe655907a8ed387294f403013e70bf to your computer and use it in GitHub Desktop.
TicketMachineParts
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